Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check for shortcode use in WordPress and parse $_GET paramater
<?php
add_action('the_posts', 'check_for_shortcode');
function check_for_shortcode($posts) {
if ( empty($posts) )
return $posts;
$found = false;
foreach ($posts as $post) {
if ( stripos($post->post_content, '[SHORT_CODE') )
$found = true;
break;
}
if ($found){
wp_register_script( 'mypluginloader',plugin_dir_url( __FILE__ ).'js/myplugin.js',array('jquery'),false,true );
$restid=0;
if ($_GET['restid']) {
$restid = (int) $_GET['restid'];
}
$param_array = array(
'restid' =>$restid
);
wp_localize_script( 'mypluginloader', 'params', $param_array );
wp_enqueue_script('mypluginloader' );
}
return $posts;
}
?>
@lkoudal

This comment has been minimized.

Copy link
Owner Author

commented May 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.