1WORDPRESS简介

WordPress 功能强大、扩展性强,这主要得益于其插件众多,易于扩充功能,基本上一个完整网站该有的功能,通过其第三方插件都能实现所有功能;

wordpress有强大的社区支持,有上千万的开发者贡献和审查wordpress,所以wordpress是安全并且活跃的。

2后台访问速度慢的原因

由于静态化较差,确切地说是真正静态化做得不好,所以在访问后台的时候wordpress会加载很多接口信息。

当你登陆wordpress后台的时候,它会连接wordpress官方接口,获取程序更新,主题更新,插件更新,语言包更新等,由于wordpress官方服务器在国外,所以说国内用户访问加载极其缓慢,有时候直接假死。

3解决方法

我们需要做的就是屏蔽掉无用的后台查询功能,把以下代码添加到你当前主题目录下的函数文件functions.php中:
缓存方式解决wordpress后台管理访问速度慢的问题插图


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//去除后台没必要的功能
<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的安装目录:


1
<span class="token function">cd</span> /var/www/
  • 1

缓存方式解决wordpress后台管理访问速度慢的问题插图1
这里主要是找到自己的wp-content目录,不同的人不一样,我的在wwwroot下,找到后直接chomd赋予权限即可!
缓存方式解决wordpress后台管理访问速度慢的问题插图2

修改后发现以及可以更新了!

缓存方式解决wordpress后台管理访问速度慢的问题插图3

如果之前代码添加出错可添加如下代码


1
2
3
4
5
6
7
8
9
// 后台禁用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后台管理访问速度慢的问题插图4

服务声明: 本网站所有发布的源码、软件和资料均为作者提供或网友推荐收集各大资源网站整理而来,仅供功能验证和学习研究使用,您必须在下载后24小时内删除。不得使用于非法商业用途,不得违反国家法律,否则后果自负!一切关于该资源商业行为与本站无关。如果您喜欢该程序,请支持购买正版源码,得到更好的正版服务。如有侵犯你的版权合法权益,请邮件或QQ:3089659733与我们联系处理删除(邮箱:ynzsy@qq.com),本站将立即更正。