WordPress get_the_author() Function

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

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.

WordPress
get_the_author();
$name = get_the_author();
CallWhat 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
WordPress
get_the_author( string $deprecated = '' ): string|null

Parameters

ParameterDescription
$deprecatedOptional. Unused. Do not pass it.

Return Value

Return ValueDescription
stringThe display name of the current post author.
empty or nullNo 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.

WordPress
<?php
$name = get_the_author();
echo 'Written by ' . esc_html( $name );
?>

How It Works

  1. get_the_author() returns the display name.
  2. The name is saved in $name.
  3. esc_html() keeps the output safe.

Example 2 — Byline in HTML

Put the name inside your own HTML tags.

WordPress
<p class="byline">
  By <?php echo esc_html( get_the_author() ); ?>
</p>

How It Works

  1. You control the HTML around the name.
  2. echo prints the returned value.
  3. Style the byline class in your CSS.

Example 3 — Post title and author

Combine the post title with the author name.

WordPress
<?php
printf(
  '%s by %s',
  esc_html( get_the_title() ),
  esc_html( get_the_author() )
);
?>

How It Works

  1. get_the_title() returns the post title.
  2. get_the_author() returns the author name.
  3. 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.

Next: get_the_author_link()

Print the display name of the current post author.

get_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