get_the_author_posts_link()WP 4.4.0

Gets the HTML code for a link to the author's post archive page. The link text will be the "displayed" name of the author. This template tag should be used inside the WordPress Loop.

Use the_author_posts_link() when you need to immediately display the result on the screen.

1 time — 0.014242 sec (extremely slow) | 50000 times — 5.91 sec (fast) | PHP 7.1.11, WP 4.9.8
Hooks from the function

Returns

String. A string, the HTML code for the link to the author's archive page of the current post.

Usage

get_the_author_posts_link();

Examples

0

#1 Display a link to the author's archive page

The link text will be the author's name:

<p>Other author's posts: <?= get_the_author_posts_link() ?></p>

This displays:

<p>Other posts by the author: <a href="/author/kama" title="Kama posts" rel="author">Kama</a></p>

The the_author_posts_link() function does the same. Only it will immediately output the result without echo.

Notes

  • Global. WP_User. $authordata The current author's data.

Changelog

Since 4.4.0 Introduced.
Since 7.0.0 Removed title attribute.

get_the_author_posts_link() code WP 7.0

function get_the_author_posts_link() {
	global $authordata;

	if ( ! is_object( $authordata ) ) {
		return '';
	}

	$author = get_the_author();
	/* translators: %s: Author's display name. */
	$title = sprintf( __( 'Posts by %s' ), $author );

	$link = sprintf(
		'<a href="%1$s" rel="author">%2$s</a>',
		esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
		$author
	);

	/**
	 * Filters the link to the author page of the author of the current post.
	 *
	 * @since 2.9.0
	 * @since 7.0.0 Added `$author` and `$title` parameters.
	 *
	 * @param string $link   HTML link.
	 * @param string $author Author's display name.
	 * @param string $title  Text originally used for a title attribute.
	 */
	return apply_filters( 'the_author_posts_link', $link, $author, $title );
}