Example 1 — Basic use
Print the email inside a comment callback.
<p>Email: <?php comment_author_email(); ?></p> How It Works
- The function prints the saved email address.
- It runs for the current comment.
- The output is plain text, not a link.

In WordPress, comment_author_email() prints the email address that the commenter typed in the form.
It prints the email as plain text. Be careful. Most visitors do not expect their email to be public.
Call it inside the comment loop, or pass a comment ID.
comment_author_email();
comment_author_email( 15 ); | Call | What it does |
|---|---|
comment_author_email() | Prints the email of the current comment author. |
comment_author_email( 15 ) | Prints the email of comment 15. |
get_comment_author_email() | Returns the email instead of printing it. |
Use this only in the admin area or for logged-in editors. Do not show emails on public pages.
comment_author_email( int|WP_Comment $comment_id = 0 ): void | Parameter | Description |
|---|---|
$comment_id | Optional. A comment ID or a WP_Comment object. Default 0, which means the current comment. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The function prints the email address. |
Three short theme examples. Each one has a sample output.
Print the email inside a comment callback.
<p>Email: <?php comment_author_email(); ?></p> Show the email only to users who can moderate comments.
<?php if ( current_user_can( 'moderate_comments' ) ) : ?>
<small><?php comment_author_email(); ?></small>
<?php endif; ?> current_user_can() checks the visitor's role.Use get_comment_author_email() to work with the value.
<?php $email = get_comment_author_email(); ?>
<?php if ( is_email( $email ) ) : ?>
<small><?php echo esc_html( $email ); ?></small>
<?php endif; ?> get_comment_author_email() returns the email as a string.is_email() checks that it looks like a real email.esc_html() makes it safe to print.Print the commenter's email as a mailto link.
10 people found this page helpful