WordPress the_author() Function

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

Definition

In WordPress, the_author() prints the display name of the author of the current post. Use it inside The Loop.

It echoes the name straight to the page. If you need the name as a string, use get_the_author().

Syntax

Call it with no arguments where you want the name to appear.

WordPress
the_author();
CallWhat it does
the_author()Prints the display name of the current post author.

No echo is needed. The function prints for you.

Full declaration
WordPress
the_author( string $deprecated = '', bool $deprecated_echo = true ): void

Parameters

ParameterDescription
$deprecatedOptional. Unused. Do not pass it.
$deprecated_echoOptional. Old option. Do not use it. Use get_the_author() when you need a string.

Return Value

Return ValueDescription
void (prints to the page)The function prints the name. Its twin get_the_author() returns the name.

WordPress Examples

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

Example 1 — Basic byline

Print the author name under a post title.

WordPress
<h2><?php the_title(); ?></h2>
<p>Posted by <?php the_author(); ?></p>

How It Works

  1. the_title() prints the post title.
  2. the_author() prints the author display name.
  3. Both run inside The Loop.

Example 2 — Inside a span

Wrap the name in a tag so you can style it.

WordPress
<span class="author-name"><?php the_author(); ?></span>

How It Works

  1. The function prints the name between your tags.
  2. Use the author-name class in CSS.
  3. The page shows only the name.

Example 3 — Use get_the_author() in an attribute

Inside an HTML attribute, return the value and escape it.

WordPress
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"
   title="Posts by <?php echo esc_attr( get_the_author() ); ?>">
  <?php the_author(); ?>
</a>

How It Works

  1. Inside title="" you need a returned value, so use get_the_author().
  2. esc_attr() escapes it for an attribute.
  3. The link text can still use the_author().

Frequently Asked Questions

It prints the display name of the current post author.
the_author() prints the name. get_the_author() returns it so you can store or escape it.
No. The function already prints the name.
No. It needs a current post. Outside The Loop use the_author_meta( 'display_name', $user_id ).
Both parameters are deprecated. You can call the_author() with no arguments.

Next: the_author_link()

Print any author profile field, such as the bio or first name.

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

9 people found this page helpful