Removing Comments RSS Feeds from WordPress

Looking at the headers for this site, I found links to four types of RSS feeds:

  1. The main posts RSS feed:

    <link rel="alternate" type="application/rss+xml" title="Jeff Vautin &raquo; Feed" href="http://jeffvautin.com/feed/" />
    
  2. The main comments RSS feed:

    <link rel="alternate" type="application/rss+xml" title="Jeff Vautin &raquo; Comments Feed" href="http://jeffvautin.com/comments/feed/" />
    
  3. Category RSS feeds, such as:

    <link rel="alternate" type="application/rss+xml" title="Jeff Vautin &raquo; Tremolo Pedal Category Feed" href="http://jeffvautin.com/category/tremolo-pedal/feed/" />
    
  4. Individual posts comment RSS feeds, like:

    <link rel="alternate" type="application/rss+xml" title="Jeff Vautin &raquo; Tremolo Pedal - Getting Back to Work Comments Feed" href="http://jeffvautin.com/2009/01/tremolo-pedal-getting-back-to-work/feed/" />
    

Since I’ve disabled comments on this site, I’d also like to stop advertising the existence of the comment feeds to my visitors. A quick web search turned up a lot of misinformation, but here’s what I found that worked.

Per these instructions, I first commented out this line in the theme’s functions.php file, to remove the main posts feed and main comment feed from all pages:

// add_theme_support( 'automatic-feed-links' );

But I actually want to keep the main posts feed, so I manually added it back in header.php, right before <?php wp_head(); ?>:

<link rel="alternate" type="application/rss+xml" title="Jeff Vautin &raquo; Feed" href="<?php bloginfo('rss2_url'); ?>" />

Next, I added this code to functions.php to to remove the comment feeds on individual sites:

// Disable comment feeds for individual posts
function disablePostCommentsFeedLink($for_comments) {
    return;
}
add_filter('post_comments_feed_link','disablePostCommentsFeedLink');

Not too complicated - three simple modifications did the trick. I tried adding this call to functions.php, in order to avoid the header.php modification, keeping all of my modifications in one file. It caused the site to go down, though, so I had to ssh in and revert my changes:

add_action('wp_head', 'addBackPostFeed');
function addBackPostFeed() {
    echo '<link rel="alternate" type="application/rss+xml" title="RSS 2.0 Feed" href="'.get_bloginfo('rss2_url').'" />'; 
}

So, next time, I won’t do this. I imagine I’ll have to recreate these changes any time there’s an update available for my theme, so having these instructions around will be useful.

Update: February 9, 2017

I moved these changes into a WordPress Child Theme.