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
评论 (0)