Using WordPress ‘get_author_link()’ PHP function

The get_author_link() WordPress PHP function returns or prints a link to the author’s posts.

Usage

To use the function, simply pass the required parameters:

get_author_link($display, $author_id, $author_nicename = '');

Parameters

  • $display (bool) – Required. Whether to display the link (true) or return it (false).
  • $author_id (int) – Required. The author’s ID.
  • $author_nicename (string) – Optional. The author’s nice name. Default: ”.

More information

See WordPress Developer Resources: get_author_link()

This function is deprecated since WordPress 2.1.0. It is advised to use get_author_posts_url() instead.

Examples

Display the link to an author’s posts by passing the author ID.

// Display the link for author with ID 3
get_author_link(true, 3);

Get the link to an author’s posts and store it in a variable.

// Get the link for author with ID 3
$author_link = get_author_link(false, 3);

Get the link to an author’s posts using the author’s nice name.

// Get the link for author with ID 3 and nicename "john_doe"
$author_link = get_author_link(false, 3, 'john_doe');

Display the author’s name and link to their posts in an anchor tag.

$author_id = 3;
$author_name = get_the_author_meta('display_name', $author_id);
$author_link = get_author_link(false, $author_id);

echo "<a href='{$author_link}'>{$author_name}</a>";

Loop through all authors and display their links to their posts.

$authors = get_users(['role' => 'author']);

foreach ($authors as $author) {
    $author_id = $author->ID;
    $author_name = $author->display_name;
    get_author_link(true, $author_id);
    echo "<br>";
}