4

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.

3
  • Just want to add a reasoning for this: Having them enabled means that scrapers like Google/Bing/Yandex/etc. are constantly querying for both every article on my site (hundreds of thousands) AND their /feed/ URLs. This is a huge burden on the server and a huge waste of resources to serve these files which are almost ever relevant and unlikely to be used meaningfully but readers (who can subscribe by email if they want to).
    – jerclarke
    Commented Mar 5, 2020 at 16:45
  • Related: wordpress.stackexchange.com/questions/56695/…
    – jerclarke
    Commented Mar 21, 2020 at 0:09
  • Related: How to disable the comments feed entirely with wp_die(): wordpress.stackexchange.com/questions/45941/…
    – jerclarke
    Commented Mar 21, 2020 at 0:56

4 Answers 4

5
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 );
6
  • Am I missing something? How/where does $for_comments get defined?
    – Pat J
    Commented Dec 11, 2013 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
    Commented Dec 11, 2013 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
    Commented Dec 11, 2013 at 21:05
  • 1
    active themes functions.php file, or in an active plugin file.
    – Shazzad
    Commented Dec 11, 2013 at 21:09
  • 2
    This isn't good. /feed still returns 200OK and the link to /feed still shows up on the post source. Commented Dec 22, 2019 at 1:41
9

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' ); 

}
4
  • 3
    Note that there's also the core __return_false() function available.
    – birgire
    Commented Feb 25, 2016 at 0:04
  • No effect whatsoever. Commented Dec 22, 2019 at 1:42
  • This worked for me to do the following: Hide the site.com/comments feed from being inserted into the header. It didn't hide the individual-post comments feeds that were in the header (site.com/posturl/comments/) in case that's what anyone was expecting (it's what I was looking for).
    – jerclarke
    Commented Mar 21, 2020 at 0:02
  • Related: How to disable the comments feed entirely with wp_die(): wordpress.stackexchange.com/questions/45941/…
    – jerclarke
    Commented Mar 21, 2020 at 0:56
1

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

0
1

I wanted to remove the comments feed and posts comments feed. As of Wordpress 5.4.2, this worked for me.

Add this into your "after_setup_theme" action.

add_theme_support('automatic-feed-links');

Add this right after that line:

add_filter( 'feed_links_show_comments_feed', '__return_false' );

After your "after_setup_theme action, add this function and filter ( I pulled this function from https://jeffvautin.com/2016/03/removing-comments-rss-feeds-from-wordpress/ blog.) It will removed the posts comments feed.

/**
 * Remove the posts comments rss feed 
 */
function disablePostCommentsFeedLink($for_comments) {
  return;
}
add_filter('post_comments_feed_link','disablePostCommentsFeedLink');

I also add this to remove those non-essential feeds

/**
 * remove non-essential rss feeds
 * 
 * This removes feeds like tags, authors, search, post type
 */
remove_action( 'wp_head', 'feed_links_extra', 3 );

I believe this will just give me the main feed. I'm not sure if this is the best way of going about this, but seems to do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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