Like the blog? Get the book »

How to Disable Comment Feeds for Individual Posts

How to Disable Comment Feeds for Individual Posts

By default, WordPress generates an RSS feed for the comments on every published post. Many sites take advantage of this by displaying a feed link next to the comments area. This enables visitors to subscribe to the comment thread and stay current with conversation. It’s convenient, simple, and super useful. For example, 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.

Disable automatic feed links

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!

6 responses

  1. Thanks for the simple hack.

  2. How do you show a link to subscribe to a post via RSS?

  3. Oh, I spoke to soon. I little wp codex searching and there I go, I now need to figure out how to customize the code.

    <?php comments_rss_link('RSS 2.0'); ?>

  4. Well, I added the code to my functions.php file, but the link is still there in the head section. It’s obviously not working in WordPress 2.9.1

  5. Tips Menulis Online

    Great! I really needed this article. Thanks a lot.

Comments are closed for this post. Contact us with any critical information.
© 2009–2024 Digging Into WordPress Powered by WordPress Monzilla Media shapeSpace