RSS Feed是WordPress的一个默认功能,允许用户订阅网站内容。然而,在某些情况下,网站管理员可能需要完全禁用这个功能,比如:
- 保护网站内容不被恶意抓取
- 减少服务器负载
- 提高网站安全性
- 本文将详细介绍如何在 WordPress 中完全禁用 RSS Feed 功能。
要彻底关闭 WordPress 的 RSS feed 功能,可以使用以下两种方法之一:
方法 1:使用代码(推荐)
将以下代码添加到当前主题(或子主题)的 functions.php 文件中,以禁用所有 RSS/Atom 源并移除头部 feed 链接:
// 移除 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);
方法 2:彻底移除 Feed 规则
使用更彻底的代码(需运行一次后删除 flush_rewrite_rules()):
// 移除头部 feed 链接
add_action( 'wp_head', 'custom_remove_feed_links', 1 );
function custom_remove_feed_links() {
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
}
// 重定向所有 feed 请求到首页
foreach ( array( 'rdf', 'rss', 'rss2', 'atom' ) as $feed ) {
add_action( 'do_feed_' . $feed, 'custom_redirect_feeds', 1 );
}
unset( $feed );
function custom_redirect_feeds() {
wp_redirect( home_url(), 302 );
exit();
}
// 删除 feed 规则
add_action( 'init', 'custom_kill_feed_endpoint', 99 );
function custom_kill_feed_endpoint() {
global $wp_rewrite;
$wp_rewrite->feeds = array();
flush_rewrite_rules(); // 运行后删除此行
}
将上述代码放入主题的 functions.php 文件中即可 。
方法 3:使用插件
- Disable Feeds 插件:完全禁用所有 RSS/Atom 源,并将请求重定向到相应 HTML 内容或显示 404 错误 。
- Remove RSS Feed 插件:通过上传插件目录并启用插件实现禁用 RSS 功能 。
完成设置后,记得删除 flush_rewrite_rules(); 这一行代码 。

主机之家



