如何在 WordPress 中禁用 RSS 源(2022)

之前写的WordPress禁用RSS Feed方法已经比较老了,现在更新一下如何在 WordPress 中禁用 RSS 源的最新方法。

如何在 WordPress 中禁用 RSS 源
如何在 WordPress 中禁用 RSS 源

使用插件禁用 RSS 源

您需要做的第一件事是安装并激活 Disable Feeds 插件。

Disable Feeds Setting
Disable Feeds Setting

在 WordPress 中手动禁用 RSS 源

WordPress主题文件functions.php中或者使用Code Snippets插件添加自定义代码:

function wpb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'" rel="nofollow">homepage</a>!') );
}
 
add_action('do_feed', 'wpb_disable_feed', 1);
add_action('do_feed_rdf', 'wpb_disable_feed', 1);
add_action('do_feed_rss', 'wpb_disable_feed', 1);
add_action('do_feed_rss2', 'wpb_disable_feed', 1);
add_action('do_feed_atom', 'wpb_disable_feed', 1);
add_action('do_feed_rss2_comments', 'wpb_disable_feed', 1);
add_action('do_feed_atom_comments', 'wpb_disable_feed', 1);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注