wordpress后台加载速度慢的解决方法

wordpress admin 2个月前 (05-27) 15次浏览 0个评论

WordPress功能强大、扩展性强,这主要得益于其插件众多,易于扩充功能,基本上一个完整网站该有的功能,通过其第三方插件都能实现所有功能。由于静态化较差,确切地说是真正静态化做得不好,所以在访问后台的时候wordpress会加载很多接口信息。

wordpress后台加载速度慢的解决方法

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

我们需要做的就是屏蔽掉无用的后台查询功能,把以下代码添加到你当前主题目录下的函数文件functions.php中。

<ol class="linenums"><li class="L0"><span class="com">//去除后台没必要的功能</span></li><li class="L1"><span class="kwd">function</span><span class="pln"> disable_dashboard_widgets</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span></li><li class="L2"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_recent_comments'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'normal'</span><span class="pun">);</span><span class="com">//近期评论 </span></li><li class="L3"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_recent_drafts'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'normal'</span><span class="pun">);</span><span class="com">//近期草稿</span></li><li class="L4"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_primary'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'core'</span><span class="pun">);</span><span class="com">//wordpress博客 </span></li><li class="L5"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_secondary'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'core'</span><span class="pun">);</span><span class="com">//wordpress其它新闻 </span></li><li class="L6"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_right_now'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'core'</span><span class="pun">);</span><span class="com">//wordpress概况 </span></li><li class="L7"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_incoming_links'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'core'</span><span class="pun">);</span><span class="com">//wordresss链入链接 </span></li><li class="L8"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_plugins'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'core'</span><span class="pun">);</span><span class="com">//wordpress链入插件 </span></li><li class="L9"><span class="pln">remove_meta_box</span><span class="pun">(</span><span class="str">'dashboard_quick_press'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'core'</span><span class="pun">);</span><span class="com">//wordpress快速发布 </span></li><li class="L0"><span class="pun">}</span><span class="pln"> </span></li><li class="L1"><span class="pln">add_action</span><span class="pun">(</span><span class="str">'admin_menu'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'disable_dashboard_widgets'</span><span class="pun">);</span></li><li class="L2"><span class="com">//移除 WordPress 加载的JS和CSS链接中的版本号</span></li><li class="L3"><span class="kwd">function</span><span class="pln"> wpdaxue_remove_cssjs_ver</span><span class="pun">(</span><span class="pln"> $src </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></li><li class="L4"><span class="kwd">if</span><span class="pun">(</span><span class="pln"> strpos</span><span class="pun">(</span><span class="pln"> $src</span><span class="pun">,</span><span class="pln"> </span><span class="str">'ver='</span><span class="pln"> </span><span class="pun">)</span><span class="pln"> </span><span class="pun">)</span></li><li class="L5"><span class="pln">$src </span><span class="pun">=</span><span class="pln"> remove_query_arg</span><span class="pun">(</span><span class="pln"> </span><span class="str">'ver'</span><span class="pun">,</span><span class="pln"> $src </span><span class="pun">);</span></li><li class="L6"><span class="kwd">return</span><span class="pln"> $src</span><span class="pun">;</span></li><li class="L7"><span class="pun">}</span></li><li class="L8"><span class="pln">add_filter</span><span class="pun">(</span><span class="pln"> </span><span class="str">'style_loader_src'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'wpdaxue_remove_cssjs_ver'</span><span class="pun">,</span><span class="pln"> </span><span class="lit">999</span><span class="pln"> </span><span class="pun">);</span></li><li class="L9"><span class="pln">add_filter</span><span class="pun">(</span><span class="pln"> </span><span class="str">'script_loader_src'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'wpdaxue_remove_cssjs_ver'</span><span class="pun">,</span><span class="pln"> </span><span class="lit">999</span><span class="pln"> </span><span class="pun">);</span></li><li class="L0"><span class="com">//移除自动保存</span></li><li class="L1"><span class="pln">wp_deregister_script</span><span class="pun">(</span><span class="str">'autosave'</span><span class="pun">);</span></li><li class="L2"><span class="com">//移除修订版本</span></li><li class="L3"><span class="pln">remove_action</span><span class="pun">(</span><span class="str">'post_updated'</span><span class="pun">,</span><span class="str">'wp_save_post_revision'</span><span class="pln"> </span><span class="pun">);</span></li><li class="L4"><span class="com">//后台禁用Google Open Sans字体,加速网站</span></li><li class="L5"><span class="pln">add_filter</span><span class="pun">(</span><span class="pln"> </span><span class="str">'gettext_with_context'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'wpdx_disable_open_sans'</span><span class="pun">,</span><span class="pln"> </span><span class="lit">888</span><span class="pun">,</span><span class="pln"> </span><span class="lit">4</span><span class="pln"> </span><span class="pun">);</span></li><li class="L6"><span class="kwd">function</span><span class="pln"> wpdx_disable_open_sans</span><span class="pun">(</span><span class="pln"> $translations</span><span class="pun">,</span><span class="pln"> $text</span><span class="pun">,</span><span class="pln"> $context</span><span class="pun">,</span><span class="pln"> $domain </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></li><li class="L7"><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln"> </span><span class="str">'Open Sans font: on or off'</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> $context </span><span class="pun">&&</span><span class="pln"> </span><span class="str">'on'</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> $text </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></li><li class="L8"><span class="pln">$translations </span><span class="pun">=</span><span class="pln"> </span><span class="str">'off'</span><span class="pun">;</span></li><li class="L9"><span class="pun">}</span><span class="kwd">return</span><span class="pln"> $translations</span><span class="pun">;</span></li><li class="L0"><span class="pun">}</span></li></ol>

 

wordpress后台加载速度慢的解决方法
故事里的归途
落叶归根才是最终的归宿地
查看


免费部落 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:wordpress后台加载速度慢的解决方法
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址