This RSS trick isn’t much of a trick at all.

In fact it’s a function that’s built right into WordPress, but one that very few know of.

We’ve all come across a post that has a long (and I mean LONG) list of comments associated with it. Keeping track of these comments can be hard for the author, let alone the readers.

post-comments

The Fix

This is why WordPress offers the following function to provide an RSS feed specifically for the comments of a particular post.

<?php post_comments_feed_link('» Comments RSS Feed'); ?>

Now there are 2 ways that you can implement this:

    1. Place it inside your theme template in the appropriate location of your choice. (The code will generate the output, so there is no need for echo )
    2. Place it inside a handler of a hook such as wp_list_comments_args. This will output the link right before where the comments our output using the wp_list_comments function. The handler should look something like this:
function my_wp_list_comments_args( $args ) {
post_comments_feed_link( '» Comments RSS Feed' );

// Don't forget to return the original arguments
return $args;
}
add_filter( 'wp_list_comments_args', 'my_wp_list_comments_args' );

How It Works

Calling this line of code will simply call the post_comments_feed_link() function that provides an RSS feed for the comments of a specific post, making it easier for your readers to keep track of those many, many comments.

Source: WP Recipes

Published by Mark Zahra

The Team Lead and Head of Support for the WP RSS Aggregator project, which forms part of the RebelCode family.

Leave a Reply

Your email address will not be published. Required fields are marked *