Is there a way to know the name of all variables passed by wp_localize_script?

Dynamic variable names are unpleasant to work with. A slightly better solution would be to use a single array / object which references each ‘instance’ using an auto-incremented integer. This isn’t a far cry from what you have already, but it keeps all you parameters inside on variable, and accessing a particular property of an … Read more

help with wp_localize_script

That’s how the wp_localize_script function works. It prints all the variables before your script is included to make sure that the variables are available to the script. If you want to print the localized variables only one time, but make sure that they are accessible for all three scripts – you can do that by … Read more

Issue with wp_localize_script

You should remove trailing slash / from 3rd line. $ait_pfad = plugin_dir_url( __FILE__ ) . ‘/assets/js/ait_buttons.js’; this should be $ait_pfad = plugin_dir_url( __FILE__ ) . ‘assets/js/ait_buttons.js’; wp_plugin_dir() function returns url including a trailing slash (“https://wordpress.stackexchange.com/”) so you should not add it again. Please read wp_plugin_dir() function reference to learn more about this function.

How can I get variable from php function and use it in wp_localize_script?

Instead of passing count through wp_localize_script you should just handle the JS logic in JS. For example in JS: var count = document.querySelectorAll( ‘input[name^=”link”]’ ).length; That would get the count of all input elements where the name attribute starts with link. It would be more performant to scope the selector by adding a class to … Read more

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.