如何隐藏WordPress主题或插件的更新提示

wordpress admin 5个月前 (04-17) 35次浏览 0个评论
文章目录[隐藏]

平常在维护WordPress时,有时候会因为一些错误或者兼容性等问题,我们不能马上升级主题或插件到最新的版本,需要保持旧版本,但是这时候会有一个问题就是每次点开后台都会看到非常显眼的小红点,影响后台体验
如何隐藏WordPress主题或插件的更新提示
在本文中我们就来说一下如何在不升级的情况下隐藏WordPress主题或插件的更新提示

隐藏所有的更新

如果你希望快速隐藏所有的更新提示,包括WordPress主题、WordPress插件、WordPress核心等的更新,可以在functions.php中添加下面的代码,表示移除掉所有的更新提示

<ol class="linenums"><li class="L0"><span class="kwd">function</span><span class="pln"> remove_core_updates</span><span class="pun">(){</span></li><li class="L1"><span class="pln">    </span><span class="kwd">global</span><span class="pln"> $wp_version</span><span class="pun">;</span><span class="kwd">return</span><span class="pun">(</span><span class="kwd">object</span><span class="pun">)</span><span class="pln"> array</span><span class="pun">(</span><span class="str">'last_checked'</span><span class="pun">=></span><span class="pln"> time</span><span class="pun">(),</span><span class="str">'version_checked'</span><span class="pun">=></span><span class="pln"> $wp_version</span><span class="pun">,);</span></li><li class="L2"><span class="pun">}</span></li><li class="L3"><span class="pln">add_filter</span><span class="pun">(</span><span class="str">'pre_site_transient_update_core'</span><span class="pun">,</span><span class="str">'remove_core_updates'</span><span class="pun">);</span><span class="pln">  </span><span class="com">//WordPress核心</span></li><li class="L4"><span class="pln">add_filter</span><span class="pun">(</span><span class="str">'pre_site_transient_update_plugins'</span><span class="pun">,</span><span class="str">'remove_core_updates'</span><span class="pun">);</span><span class="pln"> </span><span class="com">//WordPress插件</span></li><li class="L5"><span class="pln">add_filter</span><span class="pun">(</span><span class="str">'pre_site_transient_update_themes'</span><span class="pun">,</span><span class="str">'remove_core_updates'</span><span class="pun">);</span><span class="pln"> </span><span class="com">//WordPress主题</span></li></ol>

也可以通过最下面的三段代码进行控制,屏蔽某些类别的提示,比如主题或者插件,只需要注释对应的代码行便可

隐藏所有更新使用起来非常方便,不过它可以能会影响到获取以后的更新信息,并不建议长期使用

隐藏特定插件的更新提示

如果你希望长期屏蔽某个插件的更新,可以将下面的代码添加到functions.php,仅屏蔽单个插件的更新提示

<ol class="linenums"><li class="L0"><span class="kwd">function</span><span class="pln"> remove_update_notifications</span><span class="pun">(</span><span class="pln"> $value </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"> isset</span><span class="pun">(</span><span class="pln"> $value </span><span class="pun">)</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> is_object</span><span class="pun">(</span><span class="pln"> $value </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">        unset</span><span class="pun">(</span><span class="pln"> $value</span><span class="pun">-></span><span class="pln">response</span><span class="pun">[</span><span class="pln"> </span><span class="str">'elementor/elementor.php'</span><span class="pln"> </span><span class="pun">]</span><span class="pln"> </span><span class="pun">);</span><span class="pln"> </span><span class="com">//替换为禁用的插件文件</span></li><li class="L3"><span class="pln">    </span><span class="pun">}</span></li><li class="L4"><span class="pln">    </span><span class="kwd">return</span><span class="pln"> $value</span><span class="pun">;</span></li><li class="L5"><span class="pun">}</span></li><li class="L6"><span class="pln">add_filter</span><span class="pun">(</span><span class="str">'site_transient_update_plugins'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'remove_update_notifications'</span><span class="pun">);</span></li></ol>

使用本代码,需要将本文中的elementor替换为你自己的插件,通常的格式为插件文件夹里面的主php文件,你可以到WordPress的插件目录/wp-content/plugins下进行查看
如何隐藏WordPress主题或插件的更新提示

隐藏特定主题的更新提示

如果你需要隐藏某个主题的更新,可以使用下面的代码

<ol class="linenums"><li class="L0"><span class="kwd">function</span><span class="pln"> remove_theme_update_notification</span><span class="pun">(</span><span class="pln"> $value </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"> isset</span><span class="pun">(</span><span class="pln"> $value </span><span class="pun">)</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> is_object</span><span class="pun">(</span><span class="pln"> $value </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">        unset</span><span class="pun">(</span><span class="pln"> $value</span><span class="pun">-></span><span class="pln">response</span><span class="pun">[</span><span class="str">'astra'</span><span class="pun">]</span><span class="pln"> </span><span class="pun">);</span><span class="pln">  </span><span class="com">//替换为自己的主题名称</span></li><li class="L3"><span class="pln">    </span><span class="pun">}</span></li><li class="L4"><span class="pln">    </span><span class="kwd">return</span><span class="pln"> $value</span><span class="pun">;</span></li><li class="L5"><span class="pun">}</span></li><li class="L6"><span class="pln">add_filter</span><span class="pun">(</span><span class="pln"> </span><span class="str">'site_transient_update_themes'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'remove_theme_update_notification'</span><span class="pln"> </span><span class="pun">);</span></li></ol>

同样,你需要把主题名替换为自己的,可以到WordPress主题目录 /wp-content/themes 下查找,主题的名称都比较简单,一般都是原主题名,比如ocanwp、astra、generatepress等

如何隐藏WordPress主题或插件的更新提示
故事里的归途
落叶归根才是最终的归宿地
查看


免费部落 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何隐藏WordPress主题或插件的更新提示
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

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

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