I have this code for flexslider Shortcode
add_shortcode('flexslider', function($atts){
global $post;
$ids = explode(',', $atts[ids]);
$uniqid = uniqid();
wp_enqueue_script( 'shortcode_flexslider');
wp_localize_script( 'shortcode_flexslider', 'slider', array('id' => $uniqid));
foreach( $ids as $id ) {
$imgLinks = wp_get_attachment_image_src($id, large);
$imgThumb = wp_get_attachment_image_src($id, thumbnail);
$slider .= '<li><img src="'.$imgLinks[0].'">'.$imgCaptionContent.'</li>';
$carousel .= '<li><img src="'.$imgThumb[0].'"></li>';
}
$structure ='<div id="slider'.$uniqid.'" class="flexslider"><ul class="slides">'
.$slider.
'</ul></div>'.
'<div id="carousel'.$uniqid.'" class="flexslider"><ul class="slides">'
.$carousel.
'</ul></div>';
});
I put uniqid
for slider and carousel ids to can put more one flexslider Shortcode in the same post and I localize the uniqid
to shortcode_flexslider JS file to find slider and carousel ids
$('#carousel'+slider.id).flexslider({
//
asNavFor: '#slider'+slider.id
//
});
$('#slider'+slider.id).flexslider({
//
sync: '#carousel'+slider.id
//
});
The problem is when I put more one flexslider Shortcode in the same post the localized variable slider.id get the last flexslider Shortcode uniqid , so the last flexslider Shortcode is only that works ,how i can pass all flexslider Shortcode uniqid
not just the last one?