Using WordPress ‘get_comment_author_url_link’ PHP filter

The get_comment_author_url_link WordPress PHP filter allows you to modify the comment author’s returned URL link.

Usage

add_filter('get_comment_author_url_link', 'your_custom_function', 10, 1);

function your_custom_function($return) {
    // your custom code here

    return $return;
}

Parameters

  • $return (string) – The HTML-formatted comment author URL link.

More information

See WordPress Developer Resources: get_comment_author_url_link

Examples

Add rel=”nofollow” attribute

To add a rel="nofollow" attribute to the comment author’s URL link:

add_filter('get_comment_author_url_link', 'add_nofollow_to_author_url', 10, 1);

function add_nofollow_to_author_url($return) {
    $return = str_replace('<a ', '<a rel="nofollow" ', $return);
    return $return;
}

Remove http or https

To remove http or https from the comment author’s URL link:

add_filter('get_comment_author_url_link', 'remove_http_from_author_url', 10, 1);

function remove_http_from_author_url($return) {
    $return = str_replace(['http://', 'https://'], '', $return);
    return $return;
}

Add target=”_blank” attribute

To open the comment author’s URL link in a new tab:

add_filter('get_comment_author_url_link', 'open_author_url_in_new_tab', 10, 1);

function open_author_url_in_new_tab($return) {
    $return = str_replace('<a ', '<a target="_blank" ', $return);
    return $return;
}

Add custom CSS class

To add a custom CSS class to the comment author’s URL link:

add_filter('get_comment_author_url_link', 'add_custom_class_to_author_url', 10, 1);

function add_custom_class_to_author_url($return) {
    $return = str_replace('<a ', '<a class="your-custom-class" ', $return);
    return $return;
}

To change the displayed text of the comment author’s URL link:

add_filter('get_comment_author_url_link', 'change_author_url_link_text', 10, 1);

function change_author_url_link_text($return) {
    $return = preg_replace('/>(.*?)<\/a>/', '>Visit Website</a>', $return);
    return $return;
}