Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Check for shortcode use in WordPress and parse $_GET paramater
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;
if ($found){
wp_register_script( 'mypluginloader',plugin_dir_url( __FILE__ ).'js/myplugin.js',array('jquery'),false,true );
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;

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.