WordPress comment_author_link() Function

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

Definition

In WordPress, comment_author_link() prints the author name as a link to the website the commenter entered.

If the commenter did not enter a website, it prints the name as plain text. WordPress adds rel="external nofollow ugc" to the link.

Syntax

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

WordPress
comment_author_link();
comment_author_link( 15 );
CallWhat it does
comment_author_link()Prints the author name, linked to their website if there is one.
comment_author_link( 15 )Prints the linked name for comment 15.
get_comment_author_link()Returns the link HTML instead of printing it.

Use comment_author() when you want the name only, without a link.

Full declaration
WordPress
comment_author_link( 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 name, as a link when a URL exists.

WordPress Examples

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

Example 1 — With a website

Print the name of a commenter who gave a website.

WordPress
<cite class="fn"><?php comment_author_link(); ?></cite>

How It Works

  1. The commenter entered a website, so the name becomes a link.
  2. WordPress adds rel='external nofollow ugc'.
  3. The class url helps with styling.

Example 2 — Without a website

See what happens when there is no website.

WordPress
<cite class="fn"><?php comment_author_link(); ?></cite>

How It Works

  1. This commenter left the website field empty.
  2. WordPress prints only the name.
  3. You do not need an if check.

Example 3 — Return value

Use get_comment_author_link() to keep the HTML in a variable.

WordPress
<?php $link = get_comment_author_link(); ?>
<p>Posted by <?php echo $link; ?></p>

How It Works

  1. get_comment_author_link() returns the HTML.
  2. You can echo it where you need it.
  3. WordPress already escapes the name and the URL.

Frequently Asked Questions

It prints the comment author's name, linked to their website when they gave one.
It prints the name as plain text.
It tells search engines not to pass ranking credit to comment links, which reduces spam.
Use comment_author().
Use get_comment_author_link().

Next: comment_author_rss()

Print the comment author's name for use in a comments RSS feed.

comment_author_rss() 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.

13 people found this page helpful