wp_localize_script no longer working after 5.5 update

Why this function is no longer working in my theme after WordPress 5.5 updater:

add_action('wp_enqueue_scripts', function() {
    $vars = array('11' = '22');
    wp_localize_script('jquery', 'vars', $vars);
});

It used to insert JS code in the header before the 5.5 update.

Topic wp-localize-script Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.