How to use wp_localize_script in a WordPress page other than functions.php?

You cannot use wp_localize_script in page template. You have to use it in functions.php or your custom plugin, after you register your script, which is usually in the wp_enqueue_scripts action.

https://codex.wordpress.org/Function_Reference/wp_localize_script

Leave a Comment