Using WordPress ‘get_post_comments_feed_link()’ PHP function

The get_post_comments_feed_link() WordPress PHP function retrieves the permalink for the post comments feed.

Usage

get_post_comments_feed_link($post_id, $feed);

Custom example:

echo get_post_comments_feed_link(42, 'rss2');

Output:
https://example.com/post-slug/feed/

Parameters

  • $post_id int (Optional) Post ID. Default is the ID of the global $post.
  • $feed string (Optional) Feed type. Possible values include ‘rss2’, ‘atom’. Default is the value of get_default_feed().

More information

See WordPress Developer Resources: get_post_comments_feed_link()

Examples

Display comments feed link for the current post

Display the comments feed link for the current post using the default feed type.

echo get_post_comments_feed_link();

Display comments feed link for a specific post

Display the comments feed link for the post with an ID of 50 using the default feed type.

echo get_post_comments_feed_link(50);

Display the comments feed link for the current post using the ‘atom’ feed type.

echo get_post_comments_feed_link(null, 'atom');

Create an HTML link element with the comments feed link for the current post.

echo '<a href="' . get_post_comments_feed_link() . '">Comments Feed</a>';

Display the comments feed link for the current post using a custom format.

$comments_feed_link = get_post_comments_feed_link();
echo 'Check out the comments feed: ' . $comments_feed_link;