Using WordPress ‘get_comment_author_url_link()’ PHP function

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

Usage

get_comment_author_url_link( $linktext, $before, $after, $comment )

Example

echo get_comment_author_url_link( 'Visit author website', '(', ')', 45 );

Parameters

  • $linktext (string, optional) – The text to display instead of the comment author’s email address. Default: ''.
  • $before (string, optional) – The text or HTML to display before the email link. Default: ''.
  • $after (string, optional) – The text or HTML to display after the email link. Default: ''.
  • $comment (int|WP_Comment, optional) – Comment ID or WP_Comment object. Default is the current comment.

More information

See WordPress Developer Resources: get_comment_author_url_link

Examples

Display the comment author’s URL with custom text

This example displays the comment author’s URL with the custom text “Visit author website”:

echo get_comment_author_url_link( 'Visit author website' );

This example displays the comment author’s URL wrapped in parentheses:

echo get_comment_author_url_link( 'Author URL', '(', ')' );

Use the function within a loop

This example shows how to use the function within a loop to display the author’s URL for each comment:

if ( have_comments() ) {
    while ( have_comments() ) {
        the_comment();
        echo get_comment_author_url_link( 'Author URL', '<p>', '</p>' );
    }
}

Specify a specific comment by ID

This example displays the author’s URL for a specific comment with the ID 45:

echo get_comment_author_url_link( 'Visit author website', '(', ')', 45 );

Use the function with a WP_Comment object

This example shows how to use the function with a WP_Comment object:

$comment_object = get_comment( 45 );
echo get_comment_author_url_link( 'Author URL', '<p>', '</p>', $comment_object );