function check_for_shortcode($posts) {
    if ( empty($posts) )
        return $posts;

    $flag = false;

    foreach ($posts as $post) {
        if ( stripos($post->post_content, '[YOUR_SHORTCODE_HERE') )
            $flag = true;
            break;
        }

    if ($flag){
        //add scripts and styles here eg:
        //wp_enqueue_script
        //wp_enqueue_style
    }
    return $posts;
}
add_action('the_posts', 'check_for_shortcode');

Tagged with:

Filed under: wordpress

Like this post? Subscribe to my RSS feed and get loads more!