【记录】网站迁移到新服务器后CorePress后台主题设置显示空白修复
前言
前几天给网站做了个重要操作 —— 迁移到新服务器,本以为顺利切换后就能正常运营,结果打开 WordPress 后台的 CorePress 主题设置页面时,直接懵了:屏幕上一片空白,连个按钮、菜单的影子都没有!

看到空白页的第一反应,我先怀疑是不是新服务器的配置出了问题。毕竟服务器环境对 WordPress 的兼容性影响很大,比如 PHP 版本、内存限制、防火墙规则这些,都可能导致后台功能异常。
于是我顺着这个思路排查:先检查了服务器的 PHP 版本,又核对了内存限制(调整到 256M 以上),甚至把防火墙暂时关闭测试 —— 但一圈操作下来,重新刷新主题设置页面,空白问题还是没解决。
这时候才意识到,可能不是服务器的问题,而是某个细节出了岔子。既然页面空白,大概率是前端资源加载失败,于是我按下F12打开浏览器开发者工具,切换到“网络”面板,刷新页面查看资源加载情况。
果然!面板里清晰地显示有3个资源加载失败:1个CSS文件和2个JS文件,它们的共同特点是 —— 链接都指向字节跳动的CDN。点进失败的链接一看,直接跳转到“404 页面”,原来之前CorePress主题默认调用的字节跳动CDN链接失效了,导致页面缺少样式和交互脚本,自然就显示空白。

找到问题根源后,修复就很简单了
教程
因为不知道资源链接是在哪个文件,所以我们可以使用grep -rni 命令定位到需要修改的文件路径,grep 是Linux系统中强大的文本搜索工具,可递归在指定目录下递归搜索包含目标字符串的文件。
步骤:
1.打开终端,进入你的网站根目录(或需要搜索的目录):
cd /www/wwwroot/网站目录 # 替换为你的项目路径
2.执行搜索命令,查找包含失效链接片段的文件:
# 搜索包含 "lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.15.7/theme-chalk/index.min.css" 字符串的所有文件
grep -rni "lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/element-ui/2.15.7/theme-chalk/index.min.css" .

然后在宝塔里面找到这个文件,根目录/wp-content/themes/CorePress/geekframe/loadfiles.php
下列两个CDN任选其一,将loadfiles.php 中以下代码替换掉即可

1.jsDelivr CDN(推荐):
function corepress_load_style_filse_onadmin($hook)
{
wp_enqueue_style('corepressicon', THEME_LIB_PATH . '/corepressicon/iconfont.css', array(), THEME_VERSION);
if ($hook == 'post.php' || $hook == 'post-new.php') {
wp_enqueue_script('tools', THEME_JS_PATH . '/tools.js', array(), THEME_VERSION, false);
wp_enqueue_script('layer', THEME_LIB_PATH . '/layer/layer.js', array(), THEME_VERSION, false);
wp_enqueue_script('vue', 'https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js', array(), THEME_VERSION, false);
wp_localize_script('tools', 'tools', array('index' => is_home(), 'page' => is_page(), 'post' => is_single()));
wp_enqueue_script('corepress_element_js', 'https://cdn.jsdelivr.net/npm/element-ui@2.15.7/lib/index.min.js', array(), THEME_VERSION, false);
wp_enqueue_style('corepress_element_css', 'https://cdn.jsdelivr.net/npm/element-ui@2.15.7/lib/theme-chalk/index.min.css', array(), THEME_VERSION);
wp_enqueue_style('corepress_admin_css', THEME_CSS_PATH . '/admin.css', array(), THEME_VERSION);
wp_enqueue_style('editor_window', THEME_CSS_PATH . '/editor-window.css', array(), THEME_VERSION);
}
if ($hook=='toplevel_page_geekpress_setting') {
wp_enqueue_script('vue', 'https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js', array(), THEME_VERSION, false);
wp_enqueue_script('corepress_element_js', 'https://cdn.jsdelivr.net/npm/element-ui@2.15.7/lib/index.min.js', array(), THEME_VERSION, false);
wp_enqueue_style('corepress_element_css', 'https://cdn.jsdelivr.net/npm/element-ui@2.15.7/lib/theme-chalk/index.min.css', array(), THEME_VERSION);
}
}
2.unpkg备用链接:
function corepress_load_style_filse_onadmin($hook)
{
wp_enqueue_style('corepressicon', THEME_LIB_PATH . '/corepressicon/iconfont.css', array(), THEME_VERSION);
if ($hook == 'post.php' || $hook == 'post-new.php') {
wp_enqueue_script('tools', THEME_JS_PATH . '/tools.js', array(), THEME_VERSION, false);
wp_enqueue_script('layer', THEME_LIB_PATH . '/layer/layer.js', array(), THEME_VERSION, false);
wp_enqueue_script('vue', 'https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js', array(), THEME_VERSION, false);
wp_localize_script('tools', 'tools', array('index' => is_home(), 'page' => is_page(), 'post' => is_single()));
wp_enqueue_script('corepress_element_js', 'https://unpkg.com/element-ui@2.15.7/lib/index.js', array(), THEME_VERSION, false);
wp_enqueue_style('corepress_element_css', 'https://unpkg.com/element-ui@2.15.7/lib/theme-chalk/index.css', array(), THEME_VERSION);
wp_enqueue_style('corepress_admin_css', THEME_CSS_PATH . '/admin.css', array(), THEME_VERSION);
wp_enqueue_style('editor_window', THEME_CSS_PATH . '/editor-window.css', array(), THEME_VERSION);
}
if ($hook=='toplevel_page_geekpress_setting') {
wp_enqueue_script('vue', 'https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js', array(), THEME_VERSION, false);
wp_enqueue_script('corepress_element_js', 'https://unpkg.com/element-ui@2.15.7/lib/index.js', array(), THEME_VERSION, false);
wp_enqueue_style('corepress_element_css', 'https://unpkg.com/element-ui@2.15.7/lib/theme-chalk/index.css', array(), THEME_VERSION);
}
}
替换掉失效的链接后,再次打开主题设置页面即可正常访问。


1.本网站名称:柒柒零分享窝
2.本站永久网址:https://www.770a.cn/
3.本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长QQ825703967进行删除处理。
4.本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5.本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6.如无特别声明本文即为原创文章仅代表个人观点,版权归《柒柒零分享窝》所有,欢迎转载,转载请保留原文链接。
7.本站作品采用: 《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 》许可协议授权
