Support » Plugin: Simple Lightbox » Conflict with shortcode

  • Resolved linds

    (@lsterling03)



    Simple lightbox breaks when used on the same page with the following shortcode:

    Do you know why? The shortcode itself works fine, and so does everything else on the page. I see no errors in the console. But Simple Lightbox is not adding the data attributes to the gallery links when this shortcode is present on the page.

    
    function staffshortcode( $atts ) {
     
        extract(shortcode_atts(array('num' => '-1','category' =>''), $atts));
    				
        $staffquery = new WP_Query( array(
          'post_status' => 'publish',
    	  'post_type' => 'staff',
    	  'orderby' => 'menu_order',
    	  'order' => 'ASC',	
    	  'posts_per_page' => -1,
    	  'tax_query' => array(
    		array(
    			'taxonomy' => 'department',
    			'field'    => 'slug',
    			'terms'    => $category
    		),
    	     ),
    	));
       
       // the loop
        if ( $staffquery->have_posts() ) : 
    	while ( $staffquery->have_posts() ) : $staffquery->the_post(); 
       
              $temp_title = get_the_title($post->ID);
    	  $temp_excerpt = get_the_excerpt($post->ID);
    	  $temp_thumb = get_the_post_thumbnail($post->ID,'resident');
      
              $output .= '<div class="row"><div class="col-sm-4">'.$temp_thumb.'</div>
                <div class="col-sm-8"><h3>'.$temptitle.'</h3>'.$temp_excerpt.'</div></div><hr />';
              
    	endwhile; wp_reset_query(); endif;
    	
       return $output;
       
    }
    add_shortcode("staff", "staffshortcode");
Viewing 1 replies (of 1 total)
  • Plugin Author Archetyped

    (@archetyped)

    Hi, shortcodes are processed in the the_content filter hook. If your shortcode handler runs code that also applies that filter, then it will steamroll the state of the in-progress the_content filter, stopping other plugins (such as SLB) from running.

    To prevent this from happening, you need to backup the existing filter state before running your code, and then restore the filter state afterwards.

    Take a look at apply_filters() code for more details on its inner workings, and see here for details on an example of backing up the filter state in another shortcode that was inadvertently stopping plugins hooked into the the_content filter from running.

Viewing 1 replies (of 1 total)
  • The topic ‘Conflict with shortcode’ is closed to new replies.