That would print the stylesheet links into the footer. Works in most browsers, but is invalid HTML. You should hook into the action wp_head
instead and check the post content for your shortcodes. Use a priority 0
to run earlier than the the action wp_enqueue_scripts
.
add_action( 'wp_head', 'shortcode_check', 0 );
function shortcode_check() {
global $wp_query;
if ( empty ( $wp_query ) or empty ( $wp_query->posts ) )
return;
foreach ( $wp_query->posts as $post )
{
if ( FALSE !== stripos( $post->post_content, '[shortcodename' ) )
return add_action( 'wp_enqueue_scripts', 'shortcode_enqueue' );
}
}
function shortcode_enqueue() {
// enqueue scripts and stylesheets here
}