How to Display Author Information in WordPress
When developing WordPress themes, you often need to display information about post authors, such as their name, avatar, website, email, and biography. This guide covers standard methods for retrieving author data both inside the post loop (e.g., in single.php) and outside it (e.g., on author archive pages).
Inside the Post Loop
Within the main loop (e.g., while ( have_posts() ) : the_post();), you can use template tags to output the current post author's information directly.
<?php the_author(); ?>
Common author template tags include:
the_author()– Displays the author's public display name.the_author_meta( 'description' )– Outputs the author's biography (from the user profile).the_author_meta( 'user_email' )– Displays the author's email address.the_author_meta( 'user_url' )– Outputs the author's website URL.the_author_meta( 'first_name' )– Displays the author's first name.the_author_meta( 'last_name' )– Displays the author's last name.the_author_meta( 'nickname' )– Outputs the author's nickname.the_author_meta( 'ID' )– Displays the author's user ID.
Note: Older functions like the_author_description() are deprecated. The standard approach is to use the_author_meta( $field ), where $field is the user meta field name.
Outside the Loop or for a Specific Author
To retrieve information for a specific author ID, or when you are outside the post loop, use get_the_author_meta( $field, $user_id ). This function returns the value instead of echoing it.
<?php
// Get the current post author's email (inside the loop)
$author_email = get_the_author_meta( 'user_email' );
// Get the website for author with ID 1
$author_site = get_the_author_meta( 'user_url', 1 );
?>
Displaying the Author Avatar
Use the get_avatar() function to display the author's Gravatar.
<?php echo get_avatar( get_the_author_meta( 'ID' ), 96 ); ?>
The second parameter (e.g., 96) sets the avatar size in pixels.
Listing All Authors
To display a list of all site authors with their post counts, use the wp_list_authors() function.
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'show_count' => true, // Show post count
'hide_empty' => false, // Hide authors with zero posts
'echo' => true, // Echo the list
);
wp_list_authors( $args );
?>
These methods are compatible with modern WordPress versions (5.0+) and represent current best practices for theme development.