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.
Something like this should work.
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 doingwp_die()
).It also uses the
410
error code which meansGONE
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).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):Note: This doesn’t fix the
<item>
for each post in the normal RSS feedOn 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