The comments_link_feed WordPress PHP filter allows you to modify the comments permalink for the current post.
Usage
add_filter('comments_link_feed', 'your_custom_function_name'); function your_custom_function_name($comment_permalink) { // your custom code here return $comment_permalink; }
Parameters
$comment_permalink
(string) – The current comment permalink with#comments
appended.
More information
See WordPress Developer Resources: comments_link_feed
Examples
Add a query parameter to the comments feed link
This example adds a custom query parameter ref
to the comments feed link.
add_filter('comments_link_feed', 'add_ref_parameter_to_comments_link_feed'); function add_ref_parameter_to_comments_link_feed($comment_permalink) { $comment_permalink .= '&ref=my_custom_ref'; return $comment_permalink; }
Remove the #comments anchor from the comments feed link
This example removes the #comments
anchor from the comments feed link.
add_filter('comments_link_feed', 'remove_comments_anchor_from_comments_link_feed'); function remove_comments_anchor_from_comments_link_feed($comment_permalink) { return str_replace('#comments', '', $comment_permalink); }
Replace the #comments anchor with a custom anchor
This example replaces the #comments
anchor with a custom anchor #custom-comments
.
add_filter('comments_link_feed', 'replace_comments_anchor_with_custom_anchor'); function replace_comments_anchor_with_custom_anchor($comment_permalink) { return str_replace('#comments', '#custom-comments', $comment_permalink); }