缓存方式解决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">&amp;&amp;</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">&amp;&amp;</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
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。