Since WP 3.3 you can use wp_enqueue_*()
after wp_head
, and enqueued scripts and styles (if not already added to the head
of the page) would be loaded in the footer.
In short just call wp_enqueue_script()
/ wp_enqueue_style()
in your shortcode callback:
add_shortcode( 'my_shortcode', 'my_shortcode_callback' );
function my_shortcode_callback(){
//Shortcode does something, and generates mark-up to return
$html="";
//Enqueue scripts / styles
wp_enqueue_script( 'my-script' );
wp_enqueue_style( 'my-script' );
return $html;
}