Localize variable for multiple Shortcodes

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>’. … Read more

Use of global variables within plugin [closed]

Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for WordPress Development Stack Exchange. Closed 8 years ago. Improve this question I am creating my first plugin ever and I found my self having to call the same option variables within various … Read more

WP_LOCALIZE_SCRIPT doesn’t work

I am creating AJAX loading and need to use WP_LOCALIZE_SCRIPT but cannot make it work. Here is my code. I place it in functions.php wp_enqueue_script( ‘page_data’); $gallery_js_data_array = array( ‘maxPages’ => ‘$gallery_max_load = $gallery->max_num_pages;’, ‘curPage’ => ‘1’ ); wp_localize_script( ‘script’, ‘glr_dt’, $gallery_js_data_array); 2 Answers 2 You have to use the correct handle: wp_localize_script(‘page_data’, ‘glr_dt’, $gallery_js_data_array); … Read more

wp_localize_script with boolean and init

I have problem with wp_localize_script, That I cannot get boolean and int as variable wp_enqueue_script( ‘helloworld’ , ‘helloworld.js’, false, ‘1.0.0’, true); $site_config = array(); $site_config[‘boo’] = (bool)true; $site_config[‘number’] = (int)1; wp_localize_script( ‘helloworld’ , ‘site_config’ , $site_config ); Why I getting : var site_config = {“boo”:”1″,”number”:”1″}; Why not : var site_config = {“boo”:true,”number”:1}; WordPress 4.6 (latest) … Read more