WordPress the_author() Function

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.
| Call | What it does |
|---|
the_author() | Prints the display name of the current post author. |
No echo is needed. The function prints for you.
Full declaration
the_author( string $deprecated = '', bool $deprecated_echo = true ): void
Parameters
| Parameter | Description |
|---|
$deprecated | Optional. Unused. Do not pass it. |
$deprecated_echo | Optional. Old option. Do not use it. Use get_the_author() when you need a string. |
Return Value
| Return Value | Description |
|---|
| 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.
<h2><?php the_title(); ?></h2>
<p>Posted by <?php the_author(); ?></p>
Hello World
Posted by Mari Selvan
How It Works
the_title() prints the post title.the_author() prints the author display name.- Both run inside The Loop.
Example 2 — Inside a span
Wrap the name in a tag so you can style it.
<span class="author-name"><?php the_author(); ?></span>
<span class="author-name">Mari Selvan</span>
How It Works
- The function prints the name between your tags.
- Use the
author-name class in CSS. - 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.
<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>
<a href="https://example.com/author/mari-selvan/"
title="Posts by Mari Selvan">
Mari Selvan
</a>
How It Works
- Inside
title="" you need a returned value, so use get_the_author(). esc_attr() escapes it for an attribute.- 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.
About the author
Developer, cloud engineer, and technical writer
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