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.
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.
Share Improve this question asked Aug 15, 2020 at 0:52 Ahmed SaadAhmed Saad 3319 silver badges26 bronze badges1 Answer
Reset to default 1I 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.