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

    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');


  1. Have you ever considered about including a little bit more than just your articles? I mean, what you say is fundamental and everything. But think about if you added some great pictures or videos to give your posts more, “pop”! Your content is excellent but with images and videos, this site could definitely be one of the best in its field. Superb blog!

  2. Excellent site you’ve got here.. It’s difficult to find good quality writing like yours nowadays. I seriously appreciate individuals like you! Take care!!

  3. Hey there! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no back up. Do you have any methods to stop hackers?

  4. I know this web site gives quality depending articles or reviews and other information, is there any other website which provides such data in quality?

  5. Hello There. I found your blog using msn. This is a really well written article. I’ll be sure to bookmark it and come back to read more of your useful information. Thanks for the post. I’ll certainly return.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s