添加了谷歌search console但是抓取的页面后缀都带有feed,如何不使用插件的情况下完整关闭wp的RSS Feed

in Wordpress with 0 comment

方法一:通过 functions.php 禁用 RSS Feed

将以下代码添加到主题的 functions.php 文件中:

// 完全禁用 RSS Feed
function disable_feeds() {
    // 重定向所有 Feed 请求到首页
    wp_redirect( home_url(), 301 );
    exit;
}

// 禁用主要的 Feed 类型
add_action('do_feed', 'disable_feeds', 1);
add_action('do_feed_rdf', 'disable_feeds', 1);
add_action('do_feed_rss', 'disable_feeds', 1);
add_action('do_feed_rss2', 'disable_feeds', 1);
add_action('do_feed_atom', 'disable_feeds', 1);

// 移除 Feed 相关的头部链接
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);

效果:

方法二:移除 Feed 相关的 REST API 端点

如果你使用了 WordPress REST API,Feed 数据可能仍然通过 API 暴露。可以通过以下代码禁用:

// 移除 REST API 中的 Feed 端点
function disable_feeds_in_rest($endpoints) {
    if (isset($endpoints['/wp/v2/posts'])) {
        unset($endpoints['/wp/v2/posts']['feed']);
    }
    return $endpoints;
}
add_filter('rest_endpoints', 'disable_feeds_in_rest');

验证是否生效

访问 https://你的网站/feed/,检查是否重定向到首页。

查看页面源代码,确认 <head> 部分没有类似以下的 Feed 链接:

<link rel="alternate" type="application/rss+xml" title="网站标题 » Feed" href="https://你的网站/feed/" />

提醒

SEO 影响:关闭 Feed 不会影响 SEO,但确保在 Google Search Console 中提交正确的站点地图。

缓存问题:如果使用了缓存插件(如 WP Super Cache、W3 Total Cache),清除缓存后再测试。

子主题:如果使用了子主题,请将代码添加到子主题的 functions.php 中。

Responses
2016lengh.gif2016kun.gif2016db.gif2016baojin.gif2016jk.gif2016kb.gif2016qq.gif2016zj.gif2016qiao.gif2016am.gif2016kk.gif2016qd.gif2016gg.gif2016lh.gif2016wq.gif2016gz.gif2016zhh.gif2016ll.gif2016shuai.gif2016kel.gif2016zk.gif