缓存方式解决wordpress后台管理访问速度慢的问题
时间:2023年09月05日
/来源:网络
/编辑:佚名
1、WORDPRESS简介
WordPress 功能强大、扩展性强,这主要得益于其插件众多,易于扩充功能,基本上一个完整网站该有的功能,通过其第三方插件都能实现所有功能;
wordpress有强大的社区支持,有上千万的开发者贡献和审查wordpress,所以wordpress是安全并且活跃的。
2、后台访问速度慢的原因
由于静态化较差,确切地说是真正静态化做得不好,所以在访问后台的时候wordpress会加载很多接口信息。
当你登陆wordpress后台的时候,它会连接wordpress官方接口,获取程序更新,主题更新,插件更新,语言包更新等,由于wordpress官方服务器在国外,所以说国内用户访问加载极其缓慢,有时候直接假死。
3、解决方法
我们需要做的就是屏蔽掉无用的后台查询功能,把以下代码添加到你当前主题目录下的函数文件functions.php中:
缓存方式解决wordpress后台管理访问速度慢的问题插图1
//去除后台没必要的功能
<span class="token keyword">function</span> disable_dashboard_widgets<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_recent_comments'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'normal'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//近期评论
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_recent_drafts'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'normal'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//近期草稿
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_primary'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress博客
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_secondary'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress其它新闻
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_right_now'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress概况
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_incoming_links'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordresss链入链接
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_plugins'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress链入插件
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_quick_press'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress快速发布
<span class="token punctuation">}</span>
add_action<span class="token punctuation">(</span><span class="token string">'admin_menu'</span>, <span class="token string">'disable_dashboard_widgets'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
//移除 WordPress 加载的JS和CSS链接中的版本号
<span class="token keyword">function</span> wpdaxue_remove_cssjs_ver<span class="token punctuation">(</span> <span class="token variable">$src</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
if<span class="token punctuation">(</span> strpos<span class="token punctuation">(</span> <span class="token variable">$src</span>, <span class="token string">'ver='</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token variable">$src</span> <span class="token operator">=</span> remove_query_arg<span class="token punctuation">(</span> <span class="token string">'ver'</span>, <span class="token variable">$src</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token variable">$src</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
add_filter<span class="token punctuation">(</span> <span class="token string">'style_loader_src'</span>, <span class="token string">'wpdaxue_remove_cssjs_ver'</span>, 999 <span class="token punctuation">)</span><span class="token punctuation">;</span>
add_filter<span class="token punctuation">(</span> <span class="token string">'script_loader_src'</span>, <span class="token string">'wpdaxue_remove_cssjs_ver'</span>, 999 <span class="token punctuation">)</span><span class="token punctuation">;</span>
//移除自动保存
wp_deregister_script<span class="token punctuation">(</span><span class="token string">'autosave'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
//移除修订版本
remove_action<span class="token punctuation">(</span><span class="token string">'post_updated'</span>,<span class="token string">'wp_save_post_revision'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
//后台禁用Google Open Sans字体,加速网站
add_filter<span class="token punctuation">(</span> <span class="token string">'gettext_with_context'</span>, <span class="token string">'wpdx_disable_open_sans'</span>, 888, 4 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> wpdx_disable_open_sans<span class="token punctuation">(</span> <span class="token variable">$translations</span>, <span class="token variable">$text</span>, <span class="token variable">$context</span>, <span class="token variable">$domain</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token string">'Open Sans font: on or off'</span> <span class="token operator">==</span> <span class="token variable">$context</span> <span class="token operator">&&</span> <span class="token string">'on'</span> <span class="token operator">==</span> <span class="token variable">$text</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token variable">$translations</span> <span class="token operator">=</span> <span class="token string">'off'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>return <span class="token variable">$translations</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
如果提示:出现在您保存修改前,您需要将此文件设置为可写。参见CODEX来获取更多资讯。
解决方法如下
首先需要你有root权限,SSH登录,进入到wp的安装目录:
<span class="token function">cd</span> /var/www/
缓存方式解决wordpress后台管理访问速度慢的问题插图2
这里主要是找到自己的wp-content目录,不同的人不一样,我的在wwwroot下,找到后直接chomd赋予权限即可!
缓存方式解决wordpress后台管理访问速度慢的问题插图3
修改后发现以及可以更新了!
缓存方式解决wordpress后台管理访问速度慢的问题插图4
如果之前代码添加出错可添加如下代码
// 后台禁用Google Open Sans字体,加速网站
add_filter<span class="token punctuation">(</span> <span class="token string">'gettext_with_context'</span>, <span class="token string">'wpdx_disable_open_sans'</span>, 888, 4 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> wpdx_disable_open_sans<span class="token punctuation">(</span> <span class="token variable">$translations</span>, <span class="token variable">$text</span>, <span class="token variable">$context</span>, <span class="token variable">$domain</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token string">'Open Sans font: on or off'</span> <span class="token operator">==</span> <span class="token variable">$context</span> <span class="token operator">&&</span> <span class="token string">'on'</span> <span class="token operator">==</span> <span class="token variable">$text</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token variable">$translations</span> <span class="token operator">=</span> <span class="token string">'off'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">return</span> <span class="token variable">$translations</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
缓存方式解决wordpress后台管理访问速度慢的问题插图5
WordPress 功能强大、扩展性强,这主要得益于其插件众多,易于扩充功能,基本上一个完整网站该有的功能,通过其第三方插件都能实现所有功能;
wordpress有强大的社区支持,有上千万的开发者贡献和审查wordpress,所以wordpress是安全并且活跃的。
2、后台访问速度慢的原因
由于静态化较差,确切地说是真正静态化做得不好,所以在访问后台的时候wordpress会加载很多接口信息。
当你登陆wordpress后台的时候,它会连接wordpress官方接口,获取程序更新,主题更新,插件更新,语言包更新等,由于wordpress官方服务器在国外,所以说国内用户访问加载极其缓慢,有时候直接假死。
3、解决方法
我们需要做的就是屏蔽掉无用的后台查询功能,把以下代码添加到你当前主题目录下的函数文件functions.php中:
缓存方式解决wordpress后台管理访问速度慢的问题插图1
//去除后台没必要的功能
<span class="token keyword">function</span> disable_dashboard_widgets<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_recent_comments'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'normal'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//近期评论
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_recent_drafts'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'normal'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//近期草稿
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_primary'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress博客
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_secondary'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress其它新闻
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_right_now'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress概况
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_incoming_links'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordresss链入链接
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_plugins'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress链入插件
remove_meta_box<span class="token punctuation">(</span><span class="token string">'dashboard_quick_press'</span>, <span class="token string">'dashboard'</span>, <span class="token string">'core'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//wordpress快速发布
<span class="token punctuation">}</span>
add_action<span class="token punctuation">(</span><span class="token string">'admin_menu'</span>, <span class="token string">'disable_dashboard_widgets'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
//移除 WordPress 加载的JS和CSS链接中的版本号
<span class="token keyword">function</span> wpdaxue_remove_cssjs_ver<span class="token punctuation">(</span> <span class="token variable">$src</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
if<span class="token punctuation">(</span> strpos<span class="token punctuation">(</span> <span class="token variable">$src</span>, <span class="token string">'ver='</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token variable">$src</span> <span class="token operator">=</span> remove_query_arg<span class="token punctuation">(</span> <span class="token string">'ver'</span>, <span class="token variable">$src</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token variable">$src</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
add_filter<span class="token punctuation">(</span> <span class="token string">'style_loader_src'</span>, <span class="token string">'wpdaxue_remove_cssjs_ver'</span>, 999 <span class="token punctuation">)</span><span class="token punctuation">;</span>
add_filter<span class="token punctuation">(</span> <span class="token string">'script_loader_src'</span>, <span class="token string">'wpdaxue_remove_cssjs_ver'</span>, 999 <span class="token punctuation">)</span><span class="token punctuation">;</span>
//移除自动保存
wp_deregister_script<span class="token punctuation">(</span><span class="token string">'autosave'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
//移除修订版本
remove_action<span class="token punctuation">(</span><span class="token string">'post_updated'</span>,<span class="token string">'wp_save_post_revision'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
//后台禁用Google Open Sans字体,加速网站
add_filter<span class="token punctuation">(</span> <span class="token string">'gettext_with_context'</span>, <span class="token string">'wpdx_disable_open_sans'</span>, 888, 4 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> wpdx_disable_open_sans<span class="token punctuation">(</span> <span class="token variable">$translations</span>, <span class="token variable">$text</span>, <span class="token variable">$context</span>, <span class="token variable">$domain</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token string">'Open Sans font: on or off'</span> <span class="token operator">==</span> <span class="token variable">$context</span> <span class="token operator">&&</span> <span class="token string">'on'</span> <span class="token operator">==</span> <span class="token variable">$text</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token variable">$translations</span> <span class="token operator">=</span> <span class="token string">'off'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>return <span class="token variable">$translations</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
如果提示:出现在您保存修改前,您需要将此文件设置为可写。参见CODEX来获取更多资讯。
解决方法如下
首先需要你有root权限,SSH登录,进入到wp的安装目录:
<span class="token function">cd</span> /var/www/
缓存方式解决wordpress后台管理访问速度慢的问题插图2
这里主要是找到自己的wp-content目录,不同的人不一样,我的在wwwroot下,找到后直接chomd赋予权限即可!
缓存方式解决wordpress后台管理访问速度慢的问题插图3
修改后发现以及可以更新了!
缓存方式解决wordpress后台管理访问速度慢的问题插图4
如果之前代码添加出错可添加如下代码
// 后台禁用Google Open Sans字体,加速网站
add_filter<span class="token punctuation">(</span> <span class="token string">'gettext_with_context'</span>, <span class="token string">'wpdx_disable_open_sans'</span>, 888, 4 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> wpdx_disable_open_sans<span class="token punctuation">(</span> <span class="token variable">$translations</span>, <span class="token variable">$text</span>, <span class="token variable">$context</span>, <span class="token variable">$domain</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token string">'Open Sans font: on or off'</span> <span class="token operator">==</span> <span class="token variable">$context</span> <span class="token operator">&&</span> <span class="token string">'on'</span> <span class="token operator">==</span> <span class="token variable">$text</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token variable">$translations</span> <span class="token operator">=</span> <span class="token string">'off'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">return</span> <span class="token variable">$translations</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
缓存方式解决wordpress后台管理访问速度慢的问题插图5
新闻资讯 更多
- 【wordpress教程】WordPress跟踪记录访客在网站的搜索词 优化网站内容和搜索体验03-31
- 【wordpress教程】Zibll子比主题的用户中心修改头像增加支持上传PNG图片文件03-31
- 【wordpress教程】wordpress报错429怎么办03-28
- 【wordpress教程】wordpress如何批量删除指定分类目录下的所有文章03-23
- 【wordpress教程】Wordpress 在文章内容的第二段后面插入广告03-03
- 【wordpress教程】WordPress纯代码禁止发表重复标题的文章03-03
- 【wordpress教程】给wordpress博客-VIEU主题评论框添加打字特效(其他主题类似)03-03
- 【wordpress教程】wordpress自动批量定时发布插件 DX-auto-publish02-08
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法