Using WordPress ‘comment_author_url_link()’ PHP function

The comment_author_url_link() WordPress PHP function displays the HTML link of the URL of the author of the current comment.

Usage

This function allows you to display a link to the comment author’s website in your WordPress comments. If you want to change the default text or add some style before and after the link, you can do that too.

comment_author_url_link('Visit My Website', '<strong>', '</strong>');

In this case, the comment author’s website URL will be displayed as a link with the text “Visit My Website”, and the link will be bolded because it’s wrapped in <strong> tags.

Parameters

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

More information

See WordPress Developer Resources: comment_author_url_link()

Examples

Display comment author’s website without any text or styling

comment_author_url_link();

This code will simply display the comment author’s website URL as a clickable link.

comment_author_url_link('Visit Author Website');

This code will display the comment author’s website URL as a clickable link with the text “Visit Author Website”.

comment_author_url_link('Visit Author Website', '<strong>', '</strong>');

This code will display the comment author’s website URL as a clickable link with the text “Visit Author Website”, and the link will be bolded because it’s wrapped in <strong> tags.

Use a specific comment

$comment = get_comment(123); // get comment with ID 123
comment_author_url_link('Visit Author Website', '<strong>', '</strong>', $comment);

This code will display the website URL of the author of the comment with ID 123 as a bolded clickable link with the text “Visit Author Website”.

comment_author_url_link('', '<em>', '</em>');

This code will display the comment author’s website URL as a clickable link, and the link will be italicized because it’s wrapped in <em> tags.