Support » Plugin: Google Reviews Slider » Doesn’t load scripts when using shortcode in widgets or php code

  • Gert

    (@gertmeeusen)


    has_shortcode( $post->post_content, 'review_slider') only checks in the post for shortcodes and does not detect shortcodes in widgets or do_shortcode('').

    Hence, this is preventing the loading of the scripts in those cases:

    function review_slider_enqueue_scripts(){
    
      global $post;
      if( !is_a( $post, 'WP_Post' ) || !has_shortcode( $post->post_content, 'review_slider') )
        return;
    
    //enqueue styles and scripts ...
    }
    add_action( 'wp_enqueue_scripts', 'review_slider_enqueue_scripts');

    Not sure how to exactly access the widget content cause I can’t see it in $wp_registered_widgets.

Viewing 1 replies (of 1 total)
  • Gert

    (@gertmeeusen)

    I understand you don’t want to load the scripts if they are not used to reduce page loading time. An additional checkbox in admin menu might be an easy solution to overrule your if condition.

Viewing 1 replies (of 1 total)
  • The topic ‘Doesn’t load scripts when using shortcode in widgets or php code’ is closed to new replies.