Using WordPress ‘get_the_author_posts_link()’ PHP function

The get_the_author_posts_link() WordPress PHP function retrieves an HTML link to the author page of the current post’s author.

Usage

echo get_the_author_posts_link();

Parameters

  • None

More information

See WordPress Developer Resources: get_the_author_posts_link()

Examples

Display Author Posts Link in a Post Template

Display the author posts link in a post template.

if ( function_exists( 'get_the_author_posts_link' ) ) {
    echo 'Posted by: ' . get_the_author_posts_link();
}

Show the author posts link with custom text.

$author_posts_link = get_the_author_posts_link();
echo 'Check out more posts by ' . $author_posts_link . '!';

Add an icon to the author posts link using Font Awesome.

$author_posts_link = get_the_author_posts_link();
echo '<i class="fas fa-user"></i> ' . $author_posts_link;

Display the author posts link for each post in a loop.

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        echo 'Author: ' . get_the_author_posts_link() . '<br>';
    }
}

Add a conditional statement to only display the author posts link if the function exists.

if ( function_exists( 'get_the_author_posts_link' ) ) {
    echo 'Author: ' . get_the_author_posts_link();
} else {
    echo 'Author: ' . get_the_author();
}