Using WordPress ‘get_the_author_firstname()’ PHP function

The get_the_author_firstname() WordPress PHP function retrieves the first name of the author of the current post.

Usage

$author_firstname = get_the_author_firstname();
echo 'Author First Name: ' . $author_firstname;

Parameters

  • None

More information

See WordPress Developer Resources: get_the_author_firstname()

Examples

Display author first name in the loop

Display the first name of the author in the loop, with the post title and content.

if (have_posts()) {
    while (have_posts()) {
        the_post();

        echo 'Post Title: ' . get_the_title() . '<br>';
        echo 'Author First Name: ' . get_the_author_firstname() . '<br>';
        echo 'Post Content: ' . get_the_content() . '<br><br>';
    }
}

Show author first name in a custom author box

Create a custom author box below the post content with the author’s first name and biography.

$author_firstname = get_the_author_firstname();
$author_bio = get_the_author_meta('description');

echo '<div class="author-box">';
echo '<h3>About the Author: ' . $author_firstname . '</h3>';
echo '<p>' . $author_bio . '</p>';
echo '</div>';

Display author first name in an archive template

In an archive template, show the author’s first name along with the post title and date.

if (have_posts()) {
    while (have_posts()) {
        the_post();

        echo 'Post Title: ' . get_the_title() . '<br>';
        echo 'Author First Name: ' . get_the_author_firstname() . '<br>';
        echo 'Post Date: ' . get_the_date() . '<br><br>';
    }
}

Show author first name in a custom query loop

Display the first name of the author in a custom query loop, with the post title and excerpt.

$args = array(
    'posts_per_page' => 5,
);
$custom_query = new WP_Query($args);

if ($custom_query->have_posts()) {
    while ($custom_query->have_posts()) {
        $custom_query->the_post();

        echo 'Post Title: ' . get_the_title() . '<br>';
        echo 'Author First Name: ' . get_the_author_firstname() . '<br>';
        echo 'Post Excerpt: ' . get_the_excerpt() . '<br><br>';
    }
}

Display author first name in a list of recent posts

Show the author’s first name in a list of recent posts, with the post title and published date.

$recent_posts = wp_get_recent_posts(array('numberposts' => 5));
foreach ($recent_posts as $post) {
    setup_postdata($post);

    echo 'Post Title: ' . get_the_title() . '<br>';
    echo 'Author First Name: ' . get_the_author_firstname() . '<br>';
    echo 'Post Date: ' . get_the_date() . '<br><br>';
}