get_the_author_link() WordPress Function

The get_the_author_link() function in WordPress allows you to create a link to the author's page. This is useful if you want to give credit to the author of a post or page.

get_the_author_link() #

Retrieves either author’s link or author’s name.


Description

If the author has a home page set, return an HTML link, otherwise just return the author’s name.


Top ↑

Return

(string|null) An HTML link if the author's url exist in user meta, else the result of get_the_author().


Top ↑

Source

File: wp-includes/author-template.php

function get_the_author_link() {
	if ( get_the_author_meta( 'url' ) ) {
		global $authordata;

		$author_url          = get_the_author_meta( 'url' );
		$author_display_name = get_the_author();

		$link = sprintf(
			'<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
			esc_url( $author_url ),
			/* translators: %s: Author's display name. */
			esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), $author_display_name ) ),
			$author_display_name
		);

		/**
		 * Filters the author URL link HTML.
		 *
		 * @since 6.0.0
		 *
		 * @param string  $link       The default rendered author HTML link.
		 * @param string  $author_url Author's URL.
		 * @param WP_User $authordata Author user data.
		 */
		return apply_filters( 'the_author_link', $link, $author_url, $authordata );
	} else {
		return get_the_author();
	}
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.