admin管理员组文章数量:1321807
I am working on a private site where the comments need to be hidden. I know how to remove the comments feed from the header, but can anyone give me some instructions on how to disable the comments feed altogether. Because all you need to do is add /feed/ to the single post and then you can see the comments feed.
I tried creating feed-atom-comments.php, and feed-rss2-comments.php, and that still did not work.
I am working on a private site where the comments need to be hidden. I know how to remove the comments feed from the header, but can anyone give me some instructions on how to disable the comments feed altogether. Because all you need to do is add /feed/ to the single post and then you can see the comments feed.
I tried creating feed-atom-comments.php, and feed-rss2-comments.php, and that still did not work.
Share Improve this question edited Jun 15, 2013 at 11:53 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Mar 17, 2012 at 22:22 weston deboerweston deboer 5633 silver badges13 bronze badges 2- Related: Disable insertion of the sitewide comments feed URL in HTML header: wordpress.stackexchange/questions/56695/… – jerclarke Commented Mar 21, 2020 at 1:04
- Related: Disable insertion of per-post comments feed URLs in HTML header: wordpress.stackexchange/questions/190509/… – jerclarke Commented Mar 21, 2020 at 1:05
2 Answers
Reset to default 3Something like this should work.
function wpse45941_disable_feed( $comments ) {
if( $comments ) {
wp_die( 'No feed available' );
}
}
add_action('do_feed', 'wpse45941_disable_feed',1 );
add_action('do_feed_rdf', 'wpse45941_disable_feed',1 );
add_action('do_feed_rss', 'wpse45941_disable_feed',1 );
add_action('do_feed_rss2', 'wpse45941_disable_feed',1 );
add_action('do_feed_atom', 'wpse45941_disable_feed',1 );
Note: I haven't tested that at all, I just wrote it right into the answer box.
Disable only the individual-post comment feeds
An alternate version of mor7ifer's answer, this one only disables the per-post comment feeds, and not the site-wide comments feed (by checking for is_single()
before doing wp_die()
).
It also uses the 410
error code which means GONE
and seems appropriate for this use-case (at least for me, where these URLs already existed and are indexed, and I want to unequivocally tell Google and friends to stop indexing).
function wpse45941_disable_feed( $comments ) {
if( $comments and is_single() ) {
wp_die( 'Feeds for comments on single posts have been disabled.', 410 );
}
}
add_action('do_feed', 'wpse45941_disable_feed',1 );
add_action('do_feed_rdf', 'wpse45941_disable_feed',1 );
add_action('do_feed_rss', 'wpse45941_disable_feed',1 );
add_action('do_feed_rss2', 'wpse45941_disable_feed',1 );
add_action('do_feed_atom', 'wpse45941_disable_feed',1 );
Disable all comment feeds
Here's the same code with the 410
HTTP status, but it will also disable the sitewide comments feed (and shows an appropriate message):
function wpse45941_disable_feed( $comments ) {
if( $comments ) {
wp_die( 'Feeds for comments have been disabled.', 410 );
}
}
add_action('do_feed', 'wpse45941_disable_feed',1 );
add_action('do_feed_rdf', 'wpse45941_disable_feed',1 );
add_action('do_feed_rss', 'wpse45941_disable_feed',1 );
add_action('do_feed_rss2', 'wpse45941_disable_feed',1 );
add_action('do_feed_atom', 'wpse45941_disable_feed',1 );
Note: This doesn't fix the <item>
for each post in the normal RSS feed
On further inspection, I've found the following error when validating the main (posts) RSS feed for my site:
It seems WP is still inserting the comments RSS tag into the feed, but because that feed is disabled, it generates an error.
RSS still works, but I'm looking for a solution to get rid of it. This Core Trac issue is relevant
本文标签: Disable Comments Feed
版权声明:本文标题:Disable Comments Feed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742106936a2421063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论