如何关闭wordpress的feed和RSS

本站推荐通过修改代码方式关闭feed

将以下代码复制到wordpress主题的functions.php中

//关闭rss feed功能
function disable_all_feeds() {
wp_die(__('站长资料库不提供Feed,请回到首页!'));
}
add_action('do_feed', 'disable_all_feeds', 1);
add_action('do_feed_rdf', 'disable_all_feeds', 1);
add_action('do_feed_rss', 'disable_all_feeds', 1);
add_action('do_feed_rss2', 'disable_all_feeds', 1);
add_action('do_feed_atom', 'disable_all_feeds', 1);

请把以上代码中的 站长资料库 修改成自己的内容。
另外还需要注意的是wordpress还会在网页中生成feed地址,查看网页源码可看到以下两处内容

<link rel="alternate" type="application/rss+xml" title="站长资料库 &raquo; Feed" href="https://www.itszl.com/feed" />
<link rel="alternate" type="application/rss+xml" title="站长资料库 &raquo; 评论Feed" href="https://www.itszl.com/comments/feed" />

为了不让此内容显示,继续将以下代码复制粘贴到刚才的functions.php中

	
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );

最后刷新网页,以上feed的内容就不存在了,如果还存在请检查是否配置了缓存所导致!

 

0
分享到:

评论0

请先

没有账号? 忘记密码?