get_the_author_posts_link()WP 4.4.0

Retrieves an HTML link to the author page of the current post's author.

Returns an HTML-formatted link using get_author_posts_url().

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

Return

String. An HTML link to the author page, or an empty string if $authordata is not set.

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.

get_the_author_posts_link() code WP 6.5.2

function get_the_author_posts_link() {
	global $authordata;

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

	$link = sprintf(
		'<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
		esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
		/* translators: %s: Author's display name. */
		esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
		get_the_author()
	);

	/**
	 * Filters the link to the author page of the author of the current post.
	 *
	 * @since 2.9.0
	 *
	 * @param string $link HTML link.
	 */
	return apply_filters( 'the_author_posts_link', $link );
}