WordPress禁用Jquery Migrate方法

wordpress admin 5个月前 (05-03) 38次浏览 0个评论
文章目录[隐藏]

默认情况下,WordPress会加载Jquery Migrate以兼容那些使用了低版本Jquery的老网站,但是对于新网站来说,大部分都会使用最新的主题或插件,这时候Jquery Migrate就没有什么作用,为了减少加载,我们可以将其禁用掉

本文来分享下如何禁止WordPress加载Jquery Migrate
WordPress禁用Jquery Migrate方法

使用插件禁用Jquery Migrate

如果想立即禁用掉Jquery Migrate,你可以安装一款叫做 Remove jQuery Migrate 的插件
WordPress禁用Jquery Migrate方法
这是一款非常简单的小插件,安装好之后即可移除Jquery Migrate

使用代码禁用Jquery Migrate

打开外观 – 主题编辑器,编辑 functions.php

在其中添加下面的代码

<ol class="linenums"><li class="L0"><span class="kwd">function</span><span class="pln"> dequeue_jquery_migrate</span><span class="pun">(</span><span class="pln"> $scripts </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></li><li class="L1"><span class="pln">     </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln"> </span><span class="pun">!</span><span class="pln"> is_admin</span><span class="pun">()</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> </span><span class="pun">!</span><span class="pln"> empty</span><span class="pun">(</span><span class="pln"> $scripts</span><span class="pun">-></span><span class="pln">registered</span><span class="pun">[</span><span class="str">'jquery'</span><span class="pun">]</span><span class="pln"> </span><span class="pun">)</span><span class="pln"> </span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></li><li class="L2"><span class="pln">         $scripts</span><span class="pun">-></span><span class="pln">registered</span><span class="pun">[</span><span class="str">'jquery'</span><span class="pun">]-></span><span class="pln">deps </span><span class="pun">=</span><span class="pln"> array_diff</span><span class="pun">(</span></li><li class="L3"><span class="pln">             $scripts</span><span class="pun">-></span><span class="pln">registered</span><span class="pun">[</span><span class="str">'jquery'</span><span class="pun">]-></span><span class="pln">deps</span><span class="pun">,</span></li><li class="L4"><span class="pln">             </span><span class="pun">[</span><span class="pln"> </span><span class="str">'jquery-migrate'</span><span class="pln"> </span><span class="pun">]</span></li><li class="L5"><span class="pln">         </span><span class="pun">);</span></li><li class="L6"><span class="pln">     </span><span class="pun">}</span></li><li class="L7"><span class="pln"> </span><span class="pun">}</span></li><li class="L8"><span class="pln"> add_action</span><span class="pun">(</span><span class="pln"> </span><span class="str">'wp_default_scripts'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'dequeue_jquery_migrate'</span><span class="pln"> </span><span class="pun">);</span></li></ol>

保存后即可禁用Jquery Migrate
最后注意,不管你是用插件还是代码方法,添加好之后一定要测试主题和插件的功能是否能够正常使用,如出现错误,应立即撤销修改

WordPress禁用Jquery Migrate方法
故事里的归途
落叶归根才是最终的归宿地
查看


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

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

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