Skip to content

Instantly share code, notes, and snippets.

@codee47
Created October 7, 2013 16:44
Show Gist options
  • Save codee47/6871065 to your computer and use it in GitHub Desktop.
Save codee47/6871065 to your computer and use it in GitHub Desktop.
Load Scripts if Post has Short Code From http://pippinsplugins.com/load-scripts-if-post-has-short-code/
function check_for_shortcode($posts) {
if ( empty($posts) )
return $posts;
 
// false because we have to search through the posts first
$found = false;
 
// search through each post
foreach ($posts as $post) {
// check the post content for the short code
if ( stripos($post->post_content, '[YOUR_SHORTCODE') )
// we have found a post with the short code
$found = true;
// stop the search
break;
}
 
if ($found){
// $url contains the path to your plugin folder
$url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'my_login_Stylesheet',$url.'plugin_styles.css' );
 
}
return $posts;
}
// perform the check when the_posts() function is called
add_action('the_posts', 'check_for_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment