wp_script_add_data doesn’t seem to work

This is not what wp_script_add_data() does. It doesn’t support adding arbitrary attributes to the script tag. It lets you add metadata to the enqueued script, but out of the box the only key that WordPress supports is ‘conditional’, which is used for telling the script whether to load in certain versions of IE. For example, … Read more

Add_action not working in required file of functions.php

Of course there can be many reasons, but if you require ajax.php in functions.php above the hook with wp_enqueue_script( ‘myJSScript’ …); – it will not work. wp_localize_script() Works only if the script has already been added. function theme_enqueue_ajax(){ //try to add wp_enqueue_script( ‘myJSScript’ …); here wp_localize_script( ‘myJSScript’, ‘ajaxUrl’, array( ‘url’ => admin_url( ‘admin-ajax.php’ ) ) … Read more