Using WordPress ‘get_comment_author_link()’ PHP function

The get_comment_author_link() WordPress PHP function retrieves the HTML link to the URL of the author of the current comment.


echo get_comment_author_link($comment_id);


  • $comment_id (int|WP_Comment) – Optional. WP_Comment or the ID of the comment for which to get the author’s link. Default current comment.

More information

See WordPress Developer Resources: get_comment_author_link()


Display the comment author’s link in the comments section of a post.

// In your theme's comments.php
echo get_comment_author_link();

Add a custom class to the comment author link using filters. Add this code to your theme’s functions.php file.

// filter for get_comment_author_link function
function wpdocs_custom_get_comment_author_link($content) {
    $extra_classes = 'text-decoration-none text-primary fw-bold mb-0';
    return preg_replace('/url/', 'url ' . $extra_classes, $content);
add_filter('get_comment_author_link', 'wpdocs_custom_get_comment_author_link', 99);

Customize the comment author link by wrapping it in custom markup.

// In your theme's comments.php
echo '<div class="comment-author">' . get_comment_author_link() . '</div>';

Show the comment author’s avatar next to their link.

// In your theme's comments.php
echo get_avatar(get_comment_author_email()) . ' ' . get_comment_author_link();

Check if the comment author has a link before displaying it.

// In your theme's comments.php
if (get_comment_author_url()) {
    echo get_comment_author_link();
} else {
    echo get_comment_author();