<?php
/* 
= Enqueue script only when shortcode is present in post
* WordPress: 3.3.1
* Version: 1.0
* URL: elbone.com.au
* Files: functions.php
*/

// Filter post content to find occurence of shortcode
// Note that the_posts gets triggered before wp_head
add_filter('the_posts', 'elbone_conditionally_add_scripts_and_styles'); 
if (!function_exists('elbone_conditionally_add_scripts_and_styles')) {
    function elbone_conditionally_add_scripts_and_styles($posts){
        $shortcode = '[code]';
        if (empty($posts)) 
            return $posts;
	    $shortcode_found = false;
	    foreach ($posts as $post) {
		    if (stripos($post->post_content, $shortcode) !== false) {
			    $shortcode_found = true;
			    break;
		    }
	    }
	    if ($shortcode_found) {
		    // enqueue here
		    wp_enqueue_style('my-style', '/style.css');
		    wp_enqueue_script('my-script', '/script.js');
	    }
	    return $posts;
    }
}