Using WordPress ‘get_the_author_nickname()’ PHP function

The get_the_author_nickname() WordPress PHP function retrieves the nickname of the author of the current post.

Usage

echo get_the_author_nickname();

If the author’s nickname is “JohnDoe”, the output will be:

JohnDoe

Parameters

  • None

More information

See WordPress Developer Resources: get_the_author_nickname()

Examples

Displaying author’s nickname in a post loop

This example shows how to display the author’s nickname in the post loop.

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        echo 'Author: ' . get_the_author_nickname();
    }
}

Displaying author’s nickname in a single post template

This example shows how to display the author’s nickname in a single post template.

echo 'Posted by: ' . get_the_author_nickname();

Custom author credit line

This example shows how to create a custom author credit line.

echo 'This post was written by ' . get_the_author_nickname() . '.';

Displaying author’s nickname with post date

This example shows how to display the author’s nickname with the post date.

echo 'By ' . get_the_author_nickname() . ' on ' . get_the_date();

Author’s nickname in a widget

This example shows how to display the author’s nickname in a custom widget.

function custom_author_widget() {
    if ( is_single() ) {
        echo 'Article written by ' . get_the_author_nickname();
    }
}
add_action( 'wp_footer', 'custom_author_widget' );