wp_localize_script not passing the data

As it stands, your shortcode will be executed after wp_enqueue_scripts — when the post content is output. That’s why the data isn’t available to your scripts during wp_enqueue_scripts for wp_localize_script. wp_enqueue_script( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false ) You would; A) Need to … Read more

WordPress Ajax Filter

In the way you are using wp_localize_script(), the object’s name is filters, not reports; so, in filter.js you should use filters.ajax_filter. Also, you should define the variable options before use it. $( document ).ready(function() { $(“input:checkbox”).on( “change”, function() { console.log($(‘input[name=”filter[]”]:checked’).serialize()); jQuery.ajax({ url : filters.ajax_filter, type : ‘post’, data : { action : ‘filter_reports’, // You … Read more

Localize script not working in ajax

Running the localize script after the script.min.js file If that is the script you’re trying to localize, which you enqueued using the script handle mild-scripts, then you also need to use that as the script handle when calling wp_localize_script(). I.e. wp_localize_script( ‘mild-scripts’, // script handle ‘WPURLS’, // JS object name array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ … Read more