The comment_url WordPress PHP filter allows you to modify the comment author’s URL for display.
Usage
add_filter('comment_url', 'your_custom_function', 10, 2); function your_custom_function($author_url, $comment_id) { // Your custom code here return $author_url; }
Parameters
$author_url
: (string) The comment author’s URL.$comment_id
: (string) The comment ID as a numeric string.
More information
See WordPress Developer Resources: comment_url
Examples
Add a UTM parameter to the comment author’s URL
This code will append a UTM parameter to the comment author’s URL to track where the traffic is coming from.
add_filter('comment_url', 'add_utm_to_author_url', 10, 2); function add_utm_to_author_url($author_url, $comment_id) { $utm = '?utm_source=comment'; return $author_url . $utm; }
Replace HTTP with HTTPS in the comment author’s URL
This code will replace the “http://” protocol with “https://” in the comment author’s URL.
add_filter('comment_url', 'replace_http_with_https', 10, 2); function replace_http_with_https($author_url, $comment_id) { return str_replace('http://', 'https://', $author_url); }