Wordpress

How to Disable Comment Feeds for Individual Posts

By default, WordPress generates a RSS feed for the comments on every post. Many sites take advantage of this by offering the feed next to the comments area, enabling anyone to stay current with conversation. A typical feed menu for many blogs includes the following items:

  • Main Content Feed (posts, articles, etc.)
  • Main Comments Feed (all comments left on your site)
  • Comments Feed for individual posts (all comments left on a post)

This is a nice feed offering, but many people use the Subscribe to Comments plugin and find the individual-post feeds to be unnecessary. In this situation, it is easy enough to remove all comment-feed links from the theme-template files, but even after the physical links are removed, WordPress will continue to generate links in the <head> section of your pages.

This may not be a big deal, but visitors with a “feed-aware” browser such as Firefox, Opera, and Safari (I think) may be alerted to the availability of these feeds. Besides leading to potential confusion, you may not want people to actually subscribe to these feeds for whatever reason.

These individual comment-feed links are automatically created by the wp_head function when present in the <head> section of your header.php file. Fortunately, there are a couple of ways to eliminate these links from your pages. For the first technique, drop the following code into your active theme’s functions.php file:

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

That will stop the individual comment-feed links from appearing in your <head> section, but the actual feeds will remain available to anyone who is savvy enough to find them. I am pretty sure there is a way to stop the feeds themselves from being generated, but I can’t seem to remember it. Hopefully someone will remind me. 😉

While the previous method removes only the individual comment-feed links, there is another technique that will remove all feed links except for the main posts feed and main comments feed:

// kill all extra feed links in the head
remove_action('wp_head','feed_links_extra', 3);

As you might have guessed, this tasty little code slice goes into your functions.php file. Once there, it will eliminate all extraneous feed links (post-comments feed, archive feeds, tag feeds, category feeds, etc.), leaving links only for your site’s two main feeds. To kill those feed links as well, add this additional slice:

remove_action('wp_head','feed_links', 2);

When combined, these two remove_action directives are pretty much going to kill all feed links in your <head>. So use with caution!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s