Using WordPress ‘comments_rss_link()’ PHP function

The comments_rss_link() WordPress PHP function prints an RSS comment feed link for a WordPress post.

Usage

To use the comments_rss_link() function, you simply call the function and pass in the desired link text as a string. If no text is provided, the default will be ‘Comments RSS’. Here’s an example:

comments_rss_link('My Custom RSS Text');

This will output:

<a href="https://yourwebsite.com/post-name/feed/">My Custom RSS Text</a>

Parameters

  • $link_text (string) – Optional. The text that will be used for the link. The default value is ‘Comments RSS’.

More information

See WordPress Developer Resources: comments_rss_link()

This function is implemented in WordPress and there are no indications of deprecation. For the source code, please refer to the link above. A related function is post_comments_feed_link(), which also generates a comment feed link but for a specific post.

Examples

If you want the link to say something specific, you can change the default ‘Comments RSS’ text.

// Change the link text
comments_rss_link('Click here for the comment feed');

This will print:

<a href="https://yourwebsite.com/post-name/feed/">Click here for the comment feed</a>

You can call the function without any parameters, and it will use the default link text.

// Use default link text
comments_rss_link();

This will print:

<a href="https://yourwebsite.com/post-name/feed/">Comments RSS</a>

Inside a Loop

This function is usually used inside the WordPress loop, to print a comment feed link for each post.

// Inside a WordPress loop
if (have_posts()) :
    while (have_posts()) : the_post();
        comments_rss_link('Comment Feed for this post');
    endwhile;
endif;

Custom Styling

You can wrap the function inside an HTML element to apply custom styles.

// Wrap the function in a div for styling
echo '<div class="custom-rss">';
comments_rss_link('Styled Comment Feed');
echo '</div>';

Within a Template File

You can use the function in a WordPress template file, like single.php or page.php, to add the comment feed link to your posts or pages.

// Inside a template file
if (is_single() || is_page()) {
    comments_rss_link('Comment Feed for this post');
}