WordPress comment_author_email() Function

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

Definition

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.

Syntax

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

WordPress
comment_author_email();
comment_author_email( 15 );
CallWhat 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.

Full declaration
WordPress
comment_author_email( 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 email address.

WordPress Examples

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

Example 1 — Basic use

Print the email inside a comment callback.

WordPress
<p>Email: <?php comment_author_email(); ?></p>

How It Works

  1. The function prints the saved email address.
  2. It runs for the current comment.
  3. The output is plain text, not a link.

Example 2 — Only for moderators

Show the email only to users who can moderate comments.

WordPress
<?php if ( current_user_can( 'moderate_comments' ) ) : ?>
  <small><?php comment_author_email(); ?></small>
<?php endif; ?>

How It Works

  1. current_user_can() checks the visitor's role.
  2. Only moderators see the email.
  3. Other visitors see nothing.

Example 3 — Return value

Use get_comment_author_email() to work with the value.

WordPress
<?php $email = get_comment_author_email(); ?>
<?php if ( is_email( $email ) ) : ?>
  <small><?php echo esc_html( $email ); ?></small>
<?php endif; ?>

How It Works

  1. get_comment_author_email() returns the email as a string.
  2. is_email() checks that it looks like a real email.
  3. esc_html() makes it safe to print.

Frequently Asked Questions

It prints the email address saved with the current comment.
Usually no. Show it only to moderators or in the admin area.
Use get_comment_author_email(). It returns the value.
Yes. Use comment_author_email_link() for a mailto link.
The function prints an empty string.

Next: comment_author_email_link()

Print the commenter's email as a mailto link.

comment_author_email_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.

10 people found this page helpful