最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp localize script - wp_localize_script no longer working after 5.5 update

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论