WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to customize my WordPress blog in such a way that it is no more possible to access the comments feed.

Other feeds should still be available, and it should still be possible to add comments to any article.

I tried to find a plugin to do this, but what I found is a all or nothing feature, without the possibility to finely adjust which feeds are allowed and which are not.

share|improve this question
up vote 4 down vote accepted
function remove_comment_feeds( $for_comments ){
    if( $for_comments ){
        remove_action( 'do_feed_rss2', 'do_feed_rss2', 10, 1 );
        remove_action( 'do_feed_atom', 'do_feed_atom', 10, 1 );
add_action( 'do_feed_rss2', 'remove_comment_feeds', 9, 1 );
add_action( 'do_feed_atom', 'remove_comment_feeds', 9, 1 );
share|improve this answer
Am I missing something? How/where does $for_comments get defined? – Pat J Dec 11 '13 at 21:01
This is the original callback - do_action( $hook, $wp_query->is_comment_feed ), where it serve the variable $comments in the hooked function. – Shazzad Dec 11 '13 at 21:04
Yeah, I just read the snippet on the Action Reference page under do_feed_$feed: Action function argument: true (the feed is for comments) or false (it is for posts). – Pat J Dec 11 '13 at 21:05
thank you for this very fast answer. I'm not sure what to do with this code : where should I put it ? – Jérôme Dec 11 '13 at 21:07
active themes functions.php file, or in an active plugin file. – Shazzad Dec 11 '13 at 21:09

@Shazzad’s approach seems to not work when current_theme_supports( 'automatic-feed-links' ), because up to 4.3 WordPress seems to be pretty ego about feed links. You would have to remove_action( 'wp_head', 'feed_links', 2 ) hard and add your own function printing only the link for post feeds.

However, from 4.4 this seems to get easier with a brand-new filter: feed_links_show_posts_feed.

share|improve this answer

As mentioned by @glueckpress, Since 4.4 you can use the feed_links_show_comments_feed filter.

Example (in your theme functions.php file) :

add_action( 'after_setup_theme', 'head_cleanup' );

function head_cleanup(){

    // Add default posts and comments RSS feed links to head.
    add_theme_support( 'automatic-feed-links' );

    // disable comments feed
    add_filter( 'feed_links_show_comments_feed', 'return_false' ); 


// define the feed_links_show_posts_feed callback 
function return_false( ) { 
    return false; 
share|improve this answer
Note that there's also the core __return_false() function available. – birgire Feb 25 at 0:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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