wp_localize_script no longer working after 5.5 update

I just had this issue myself and was able to fix it by assigning it to the script that required the data and not to “jquery”, example below: wp_localize_script(‘jquery’, ‘vars’, $vars); wp_localize_script( ‘replace-with-your-script-name’, ‘vars’, $vars); To clarify: This would be the same name that was used to identify in wp_enqueue_script() and should match it.

Translate javascript with WordPress built-in localization API for static strings

wp_localize_script() defines a variable in the global JS scope – in the case of your code, the object is placed in a globally-scoped variable with the identifier MediaFolders. In your load event callback you are also defining a variable with the identifier MediaFolders scoped to it’s encapsulating function body – so when you use the … Read more

in jquery read a multidimensional array via wp_localize_script()

Accessing the data var data0A = theme_metadata[0].dataA, data0B = theme_metadata[0].dataB, data1A = theme_metadata[1].dataA, data1B = theme_metadata[1].dataB; [Update] Iterating over numeric arrays in JS While the initial question was still somewhat pertinent to WordPress, your follow-up really is a question purely concerning javascript syntax. Anyway, this is how: var dataA, dataB; for ( var i = … Read more

How do I pass the template url to javascript in the ADMIN area of my theme?

If you want to use the variables from the admin.js script, and you want to be sure it works you have to use as handle for wp_localize_script the handle of the script that have to use data call wp_localize_script after that script is enqueued wp_enqueue_script( ‘some_handle’ ); wp_enqueue_script(“admin”, $adminDir.”js/admin.js”, false, “1.0”); $translation_array = array( ‘some_string’ … Read more

Using wp_localize_script to get data from cpt and pass it to maplace-js locations

You don’t need to use json_encode() when using wp_localize_script(). The last argument of wp_localize_script() should be a PHP array. This will be converted to JSON for you. So to resolve the issue, remove this line: $location_json = json_encode($location_array); And change wp_localize_script() to use $location_array: wp_localize_script(‘sage/main.js’, ‘locationJSON’, $location_array); Because $location_array had been double-encoded the locationJSON variable … Read more