Thursday 19 September 2013

Load the style only if the shortcode is found

Load the style only if the shortcode is found

I'm writing my first wordpress plugin. How can I load javascript into head
section from the content?
Basically to load a style we call this
function theme_name_scripts() {
wp_enqueue_style('wpscf-styles10', plugin_dir_url( __FILE__ ) .
'css/style.css');
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
But I need to load the style ONLY if the shortcode is found in the text.
So I'm using the following
add_filter('the_content','wpscf_render_plugin');
function wpscf_render_plugin($content) {
if($condition_which_checks_if_shortcode_found) {
//load the scripts here
}
}
How can I do that?
Thanks

No comments:

Post a Comment