Example 1 — Default link
Print the email as a link.
<p><?php comment_author_email_link(); ?></p> How It Works
- WordPress builds a
mailto:link. - The link text is the email address.
- If there is no email, the paragraph stays empty.

In WordPress, comment_author_email_link() prints a mailto link for the email address of the comment author.
It prints the link only when the comment has a real email. You can change the link text and add text before and after the link.
Call it with no arguments, or set the link text and the text around it.
comment_author_email_link();
comment_author_email_link( 'Email me' );
comment_author_email_link( 'Email', '(', ')' ); | Call | What it does |
|---|---|
comment_author_email_link() | Prints the email as a link. The email is also the link text. |
comment_author_email_link( 'Email me' ) | Prints a link with your own text. |
comment_author_email_link( 'Email', '(', ')' ) | Adds text before and after the link. |
Nothing is printed if the comment has no email address.
comment_author_email_link( string $link_text = '', string $before = '', string $after = '', int|WP_Comment $comment = null ): void | Parameter | Description |
|---|---|
$link_text | Optional. Text to show instead of the email address. |
$before | Optional. Text or HTML to print before the link. |
$after | Optional. Text or HTML to print after the link. |
$comment | Optional. A comment ID or WP_Comment object. Default is the current comment. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The function prints the link, or nothing if there is no email. |
Three short theme examples. Each one has a sample output.
Print the email as a link.
<p><?php comment_author_email_link(); ?></p> mailto: link.Use friendly text for the link.
<?php comment_author_email_link( 'Email the author' ); ?> mailto: address stays the same.Wrap the link with your own text.
<?php comment_author_email_link( 'Email', '[', ']' ); ?> Print the IP address of the current comment author.
11 people found this page helpful