Using WordPress ‘get_the_author_meta()’ PHP function

The get_the_author_meta() WordPress PHP function retrieves the requested data of the author of the current post.

Usage

get_the_author_meta( $field, $user_id );

Parameters

  • $field (string) – Optional. The user field to retrieve. Default: ”.
  • $user_id (int|false) – Optional. User ID. Defaults to the current post author. Default: false.

More information

See WordPress Developer Resources: get_the_author_meta()

Examples

Display the author bio with line breaks

This example will display the author’s bio (description) while keeping the line breaks.

echo nl2br(get_the_author_meta('description'));

Get the author ID

This example retrieves the author ID of the current post, both inside and outside the loop.

// Outside loop
global $post;
$author_id = $post->post_author;

// Inside loop
$author_id = get_the_author_meta('ID');

Show a user’s display name with their email address linked

This example will display the email address for user ID 25 and echo it using their display name as the anchor text.

<p>Email the author: <a href="mailto:<?php echo get_the_author_meta('user_email', 25); ?>"><?php the_author_meta('display_name', 25); ?></a></p>

Get a user’s email address

This example will get the email address for the author of the current post and store it in the $user_email variable for further use.

$user_email = get_the_author_meta('user_email');

Display author’s description with line breaks and wrapping paragraphs

This example will display the author’s description while keeping line breaks and wrapping its paragraphs into <p> tags.

echo wpautop(get_the_author_meta('description'));