2

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.

2

Something 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.

| improve this answer | |
  • I just tested this for a client of mine, and so far seems to be working perfectly. The specific problem was to turn off comments feed for individual posts. Thank you :-) – Lars Koudal Aug 8 '12 at 15:14
  • Note that this will disable ALL comments feeds, including the main one at site.com/commentes/feed/ and not just the per-post ones like site.com/postpermalink/feed/. Maybe you want that, but it's important to note. (I'm hoping for a solution that keeps the global feed but not the per-post ones) – jerclarke Mar 21 at 0:32
0

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 );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.