You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress版本更新致网站崩溃 求助排查解决

WordPress更新后页面大面积空白的解决办法

问题描述

我的网站已2-3年未更新WordPress版本,此次更新后网站彻底崩溃,页面大面积空白,仅保留约5%的原有内容。搜索发现WP终止jQuery旧版本支持导致大量网站故障,我通过开发者控制台记录了jQuery错误,尝试安装并启用「Enable jQuery Migrate Helper」插件,但完全无效,求解决办法。

控制台错误日志

jquery-migrate.min.js?ver=3.3.2:2 JQMIGRATE: Migrate is installed, version 3.3.2
jquery.tools.min.js?ver=6.0.2:13 Uncaught TypeError: Cannot read properties of undefined (reading 'msie')
    at jquery.tools.min.js?ver=6.0.2:13:204
    at jquery.tools.min.js?ver=6.0.2:13:2814
VM722:2 Uncaught SyntaxError: Unexpected token '<'
    at t.activateScript (rocket-loader.min.js:1:11855)
    at rocket-loader.min.js:1:11052
    at t.run (rocket-loader.min.js:1:11259)
    at rocket-loader.min.js:1:11156
    at HTMLScriptElement.<anonymous> (rocket-loader.min.js:1:670)
jquery.min.js?ver=3.6.0:2 jQuery.Deferred exception: jQuery(...).overlay is not a function TypeError: jQuery(...).overlay is not a function
    at HTMLDocument.<anonymous> (.../wp-content/plugins/wpcomic/assets/jquery.overlay.js?ver=6.0.2:2:22)
    at e (.../wp-includes/js/jquery/jquery.min.js?ver=3.6.0:2:30038)
    at t (.../wp-includes/js/jquery/jquery.min.js?ver=3.6.0:2:30340) undefined
jquery.min.js?ver=3.6.0:2 Uncaught TypeError: jQuery(...).overlay is not a function
    at HTMLDocument.<anonymous> (jquery.overlay.js?ver=6.0.2:2:22)
    at e (jquery.min.js?ver=3.6.0:2:30038)
    at t (jquery.min.js?ver=3.6.0:2:30340)
jquery.min.js?ver=3.6.0:2 Uncaught Error: Syntax error, unrecognized expression: [data-hover-bg^=#]
    at se.error (jquery.min.js?ver=3.6.0:2:13639)
    at se.tokenize (jquery.min.js?ver=3.6.0:2:21650)
    at se.compile (jquery.min.js?ver=3.6.0:2:21753)
    at se.select (jquery.min.js?ver=3.6.0:2:22998)
    at se (jquery.min.js?ver=3.6.0:2:7116)
    at se.matchesSelector (jquery.min.js?ver=3.6.0:2:13211)
    at S.filter (jquery.min.js?ver=3.6.0:2:24737)
    at j (jquery.min.js?ver=3.6.0:2:24623)
    at s.fn.init.is (jquery.min.js?ver=3.6.0:2:25232)
    at HTMLDivElement.<anonymous> (init.js?ver=7.0.7:201:12)

分步解决方法

1. 修复jquery.tools的msie错误

jquery.tools是老旧插件,新版jQuery移除了$.browser.msie浏览器检测属性导致报错。可以手动注入兼容代码:
在主题的functions.php中添加以下代码,在jquery.tools加载前执行兼容逻辑:

function add_jquery_browser_fix() {
    wp_add_inline_script('jquery', '(function($) {
        if (!$.browser) {
            $.browser = {};
            $.browser.msie = false;
            var ua = navigator.userAgent.toLowerCase();
            if (ua.indexOf("msie") !== -1 || ua.indexOf("trident") !== -1) {
                $.browser.msie = true;
            }
        }
    })(jQuery);', 'before');
}
add_action('wp_enqueue_scripts', 'add_jquery_browser_fix', 5);

2. 修复选择器语法错误

新版jQuery要求属性选择器的数值必须加引号,找到init.js?ver=7.0.7中的[data-hover-bg^=#],修改为[data-hover-bg^="#"]。如果是主题文件直接编辑对应JS;如果是插件文件,优先更新插件,或用自定义脚本覆盖:

jQuery(document).ready(function($) {
    $('[data-hover-bg^="#"]').each(function() {
        // 保留原有的功能代码
    });
});

3. 禁用Cloudflare Rocket Loader(若使用)

控制台的Unexpected token '<'错误大概率是Cloudflare的Rocket Loader延迟加载脚本导致的,进入Cloudflare后台暂时禁用该功能,清空CDN缓存后再测试。

4. 替换或更新老旧插件

wpcomic插件的jquery.overlay.js依赖已过时的jquery.tools,优先尝试更新wpcomic到最新版本;若无更新,更换为支持新版jQuery的漫画插件。

5. 临时降级jQuery(应急方案)

如果以上方法暂时无法实施,可强制WordPress加载旧版兼容jQuery:
在functions.php中添加:

function downgrade_jquery_for_compatibility() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'https://code.jquery.com/jquery-1.12.4.min.js', array(), '1.12.4');
    wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'downgrade_jquery_for_compatibility');

注意:这只是临时方案,长期必须升级主题和插件适配新版jQuery。

6. 清空所有缓存

清空WordPress后台缓存、浏览器缓存、CDN缓存,确保加载最新脚本文件,避免缓存旧的冲突代码。

内容的提问来源于stack exchange,提问作者Cake Princess

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 18:15:49