Using WordPress ‘get_the_author_email()’ PHP function

The get_the_author_email() WordPress PHP function retrieves the email address of the author of the current post.

Usage

$email = get_the_author_email();
echo 'Author email: ' . $email;

Parameters

  • None

More information

See WordPress Developer Resources: get_the_author_email()

Examples

Displaying author email in a post loop

This example shows how to display the author’s email address for each post in a WordPress loop.

if (have_posts()) :
  while (have_posts()) : the_post();
    $author_email = get_the_author_email();
    echo 'Author email: ' . $author_email;
  endwhile;
endif;

Displaying author email in author archive page

This example demonstrates how to display the author’s email address on their archive page.

$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
echo 'Email: ' . $curauth->user_email;

This example shows how to create a mailto link using the author’s email address.

$author_email = get_the_author_email();
echo '<a href="mailto:' . $author_email . '">Email the author</a>';

Displaying author email in a custom function

This example demonstrates how to use the get_the_author_email() function inside a custom function to return the author’s email address.

function custom_get_author_email() {
  $author_email = get_the_author_email();
  return $author_email;
}
echo 'Author email: ' . custom_get_author_email();

Displaying author email along with other author metadata

This example shows how to display the author’s email address alongside their name and website.

$author_email = get_the_author_email();
$author_name = get_the_author_meta('display_name');
$author_website = get_the_author_meta('url');

echo 'Author: ' . $author_name . '<br>';
echo 'Email: ' . $author_email . '<br>';
echo 'Website: <a href="' . $author_website . '">' . $author_website . '</a>';