The post_comments_feed_link_html WordPress PHP filter allows you to modify the comment feed link anchor tag for a specific post.
Usage
add_filter('post_comments_feed_link_html', 'your_custom_function', 10, 3); function your_custom_function($link, $post_id, $feed) { // your custom code here return $link; }
Parameters
- $link (string): The complete anchor tag for the comment feed link.
- $post_id (int): Post ID.
- $feed (string): The feed type. Possible values include ‘rss2’, ‘atom’, or an empty string for the default feed type.
More information
See WordPress Developer Resources: post_comments_feed_link_html
Examples
Change feed link text
To change the text of the comment feed link anchor tag:
add_filter('post_comments_feed_link_html', 'change_feed_link_text', 10, 3); function change_feed_link_text($link, $post_id, $feed) { // Replace the link text $link = str_replace('Comment Feed', 'New Link Text', $link); return $link; }
Add a CSS class
To add a CSS class to the comment feed link anchor tag:
add_filter('post_comments_feed_link_html', 'add_css_class_to_feed_link', 10, 3); function add_css_class_to_feed_link($link, $post_id, $feed) { // Add a CSS class to the link $link = str_replace('<a ', '<a class="my-css-class" ', $link); return $link; }
Change the feed type
To change the feed type of the comment feed link:
add_filter('post_comments_feed_link_html', 'change_feed_type', 10, 3); function change_feed_type($link, $post_id, $feed) { // Change the feed type to Atom $link = str_replace('?feed=rss2', '?feed=atom', $link); return $link; }
Remove the feed link
To remove the comment feed link completely:
add_filter('post_comments_feed_link_html', 'remove_feed_link', 10, 3); function remove_feed_link($link, $post_id, $feed) { // Remove the link $link = ''; return $link; }
Add a custom attribute
To add a custom attribute to the comment feed link anchor tag:
add_filter('post_comments_feed_link_html', 'add_custom_attribute', 10, 3); function add_custom_attribute($link, $post_id, $feed) { // Add a custom attribute to the link $link = str_replace('<a ', '<a data-custom-attr="value" ', $link); return $link; }