javascript - How to check shortcode with variables using has_shortcode() in WordPress -


i'm trying following approach enqueue css/js files within plugin when shortcode being used:

add_action( 'wp_enqueue_scripts', function() {     global $post;      if( is_a( $post, 'wp_post' ) && has_shortcode( $post->post_content, 'shortcode') ) {         //add css/js here     } } ); 

now problem i'm having code if use shortcode [shortcode] works fine when pass variable within shortcode [shortcode id="1" class="something"] cannot detect , hence doesn't add css/js files.

can bit?

you can try code,

   add_action( 'wp_enqueue_scripts', function( $id, $class) {    global $post;       if( is_a( $post, 'wp_post' ) && has_shortcode( $post->post_content,   'shortcode') ) {        //enqueue css/js files here      }   } 

then use shortcode: [shortcode id="1" class="something"]


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -