WordPress comment_author_url() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, comment_author_url() prints the website address that the commenter typed in the form.

It prints only the URL text. It does not build a link. Use it inside an href or when you need the address by itself.

Syntax

Call it inside the comment loop, or pass a comment ID.

WordPress
comment_author_url();
comment_author_url( 15 );
CallWhat it does
comment_author_url()Prints the website URL of the current comment author.
comment_author_url( 15 )Prints the URL for comment 15.
get_comment_author_url()Returns the URL instead of printing it.

If the commenter left the website empty, nothing is printed.

Full declaration
WordPress
comment_author_url( int|WP_Comment $comment_id = 0 ): void

Parameters

ParameterDescription
$comment_idOptional. A comment ID or a WP_Comment object. Default 0, which means the current comment.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the URL.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Print the URL

Print the website as text.

WordPress
<p>Website: <?php comment_author_url(); ?></p>

How It Works

  1. The function prints the saved URL.
  2. It prints text only, not a link.
  3. The URL is already cleaned by WordPress.

Example 2 — Use inside a link

Build your own link with the URL.

WordPress
<a href="<?php comment_author_url(); ?>" rel="nofollow ugc">Visit site</a>

How It Works

  1. The URL goes inside href.
  2. rel="nofollow ugc" is added by you.
  3. Use this style when you want custom link text.

Example 3 — Check first

Show the link only if there is a URL.

WordPress
<?php if ( get_comment_author_url() ) : ?>
  <a href="<?php comment_author_url(); ?>" rel="nofollow ugc">Website</a>
<?php endif; ?>

How It Works

  1. get_comment_author_url() returns the URL or an empty string.
  2. The link prints only when a URL exists.
  3. This avoids empty links.

Frequently Asked Questions

It prints the website URL that the comment author entered.
No. It prints only the URL text. Use comment_author_url_link() or comment_author_link() for links.
It prints an empty string.
Use get_comment_author_url().
Yes. Add rel="nofollow ugc" when you build your own link.

Next: comment_author_url_link()

Print the commenter's website as a clickable link.

comment_author_url_link() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful