Disable comments feed, but not the others

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.

Read More

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.

Related posts

4 comments

  1. 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 );
    
  2. 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' ); 
    
    }
    
  3. 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.

Comments are closed.