WordPress get_the_author() Function

Definition
In WordPress, get_the_author() returns the display name of the author of the current post. Use it inside The Loop.
It returns the name as a string. It does not print it. If you only want to print the name, use the_author().
Syntax
Call it with no arguments and store the result.
get_the_author();
$name = get_the_author();
| Call | What it does |
|---|
get_the_author() | Returns the display name of the current post author. |
$name = get_the_author() | Saves the name in a variable so you can test it or escape it. |
Use esc_html() when you print the returned name.
Full declaration
get_the_author( string $deprecated = '' ): string|null
Parameters
| Parameter | Description |
|---|
$deprecated | Optional. Unused. Do not pass it. |
Return Value
| Return Value | Description |
|---|
| string | The display name of the current post author. |
| empty or null | No author data is available (for example, outside The Loop). |
WordPress Examples
Three short theme examples. Each one has a sample output.
Example 1 — Store the name
Save the author name and print a sentence.
<?php
$name = get_the_author();
echo 'Written by ' . esc_html( $name );
?>
How It Works
get_the_author() returns the display name.- The name is saved in
$name. esc_html() keeps the output safe.
Example 2 — Byline in HTML
Put the name inside your own HTML tags.
<p class="byline">
By <?php echo esc_html( get_the_author() ); ?>
</p>
How It Works
- You control the HTML around the name.
echo prints the returned value.- Style the
byline class in your CSS.
Example 3 — Post title and author
Combine the post title with the author name.
<?php
printf(
'%s by %s',
esc_html( get_the_title() ),
esc_html( get_the_author() )
);
?>
Hello World by Mari Selvan
How It Works
get_the_title() returns the post title.get_the_author() returns the author name.printf() joins both values.
Frequently Asked Questions
It returns the display name of the current post author as a string.
get_the_author() returns the name. the_author() prints the name.
Not reliably. It needs a current post. Outside The Loop, use get_the_author_meta( 'display_name', $user_id ).
It is an old argument that WordPress no longer uses. Leave it out.
Yes. Use esc_html( get_the_author() ) when you print it.
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