更好的WordPress主题

WordPress 完全禁用 RSS Feed 的最佳方法

摘要:在某些情况下,网站管理员可能需要完全禁用feed功能

RSS Feed 是 WordPress 的一个默认功能,允许用户订阅网站内容。然而,在某些情况下,网站管理员可能需要完全禁用这个功能,比如:

  • 保护网站内容不被恶意抓取
  • 减少服务器负载
  • 提高网站安全性

本文将详细介绍如何在 WordPress 中完全禁用 RSS Feed 功能。


WordPress 完全禁用 RSS Feed 的最佳方法

复制以下代码到主题目录下的 functions.php 文件中即可

// 移除 feed 链接
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);

// 禁用 feed
function tb_disable_all_feeds() {
    wp_die('RSS feeds 已被禁用。');
}
add_action('do_feed', 'tb_disable_all_feeds', 1);
add_action('do_feed_rdf', 'tb_disable_all_feeds', 1);
add_action('do_feed_rss', 'tb_disable_all_feeds', 1);
add_action('do_feed_rss2', 'tb_disable_all_feeds', 1);
add_action('do_feed_atom', 'tb_disable_all_feeds', 1);
add_action('do_feed_rss2_comments', 'tb_disable_all_feeds', 1);
add_action('do_feed_atom_comments', 'tb_disable_all_feeds', 1);

本文属原创,转载请注明原文:https://themebetter.com/wordpress-disable-feed.html

感觉很棒,欢迎打赏~

9 打赏
分享到:

评论 (0)

登录后评论
注:有关主题的售前售后请 提交工单

建站!你有充足的理由选择我们

世界上超过43%的网站是由WordPress搭建,而我们是国内最靠谱的WordPress主题开发商
在线工单