wp_localized_script is not defined when called via jquey ajax

I am struggling to get my ajax request to work. It fails when I fire my $ajax and I get this error… Uncaught ReferenceError: feature_ajax is not defined This is my functions.php // load our frontend modifiers require_once(__DIR__ . ‘/lib/Frontend.lib.php’); This is my Frontend.lib.php class php… class Frontend { /** frontend constructor */ public function … Read more

w3 total cache minification breaks wp_localize_script() [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 7 years ago. Improve this question I am trying to configure W3 total cache plugin to speed up my site. The minify option is great but I … Read more

Do I need to escape data passed to wp_localize_script()?

Title pretty much says it all. I took a look at the source, and I didn’t see any escaping being done. But, I can’t say for sure. wp_localize_script( ‘script-hook’, ‘object_name’, array( ‘param_1’ => $value_1, // This? ‘param_2′ => esc_js( $value_2 ) // Or, this? ) ); 1 1 As far as I know wp_localize_script doesn’t … Read more

Creating Multiple wp_localize_script for Shortcode?

I have a shortcode that displays recent WooCommerce products in a carousel, however i would like the end user to be able to use the shortcode multiple times on the same page, currently when this happens the jQuery carousel has conflicts. Here is the code i’m using for the shortcode, function recent_products_slider_func($atts) { global $woocommerce_loop; … Read more

Multiple wp_localize_script

Is it possible to localize a script more than once? I want to send two separate arrays of params. Or is it only possible to localize a script once, in which case, I’ll have to combine the arrays? I’d like to do something like this: wp_localize_script(‘my-handle’, ‘my_object1’, $data1 ); wp_localize_script(‘my-handle’, ‘my_object2’, $data2 ); 1 1 … Read more

Passing boolean values with wp_localize_script

I am using wp_localize_script to pass a couple of values from my theme options to a javascript file. First I got the values from my theme options: $options = get_option(‘theme’); $flex_auto = $options[“slide-auto”]; $flex_animation = $options[“slide-animation”]; $flex_direction = $options[“slide-direction”]; Then I used wp_localize_script to create my array of values. wp_enqueue_script(‘flexslider’); wp_localize_script(‘flexslider’, ‘flex_vars’, array( ‘flex_auto’ => … Read more

Is there a JavaScript API? How to access public and private data in JS?

According to this post there is no built-in JavaScript API for WordPress. Therefore developers who want to build on AJAX seem to come up all with their own solution which doesn’t seem right to me. What I really miss apart from fetching posts or whatever data with a built-in API is a small set of … Read more

How to intercept already localized scripts

If a plugin uses some script (prominent example: jQuery UI Datepicker), but you’re not happy with how the script renders the output, then there’re two possibilities: 1. Unregister the script > Add your own version So first you’d need to check the handle, then find the priority and the hook (wp_enqueue_scripts, login_enqueue_scripts, etc.) … you … Read more

Is it possible to use wp_localize_script to create global JS variables without a specific script handle?

Can we somehow use wp_localize_script() to create global js variables without a specific script handle which can be accessed from all the js files, even if the js scripts are not enqueued properly by using wp_enqueue_script ? This is the code I am using which creates varibale for ‘ajaxscript’ handle, so I cant access the … Read more