
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.
comment_author_link();
comment_author_link( 15 );
| Call | What 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
comment_author_link( int|WP_Comment $comment_id = 0 ): void
Parameters
| Parameter | Description |
|---|
$comment_id | Optional. A comment ID or a WP_Comment object. Default 0, which means the current comment. |
Return Value
| Return Value | Description |
|---|
| void | Nothing 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.
<cite class="fn"><?php comment_author_link(); ?></cite>
<cite class="fn"><a href='https://janedoe.example' rel='external nofollow ugc' class='url'>Jane Doe</a></cite>
How It Works
- The commenter entered a website, so the name becomes a link.
- WordPress adds
rel='external nofollow ugc'. - The class
url helps with styling.
Example 2 — Without a website
See what happens when there is no website.
<cite class="fn"><?php comment_author_link(); ?></cite>
<cite class="fn">Sam Lee</cite>
How It Works
- This commenter left the website field empty.
- WordPress prints only the name.
- You do not need an
if check.
Example 3 — Return value
Use get_comment_author_link() to keep the HTML in a variable.
<?php $link = get_comment_author_link(); ?>
<p>Posted by <?php echo $link; ?></p>
<p>Posted by <a href='https://janedoe.example' rel='external nofollow ugc' class='url'>Jane Doe</a></p>
How It Works
get_comment_author_link() returns the HTML.- You can echo it where you need it.
- 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().
About the author
Developer, cloud engineer, and technical writer
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