get_the_author_link()WP 3.0.0

Returns a link (A tag) to the author's website. The anchor of the link will be the author's name.

Used inside the WordPress Loop.

If the author did not specify a website in the profile, only their name will be returned, without a link.

Returns a link for processing in PHP (does not output to the screen).

Hooks from the function

Returns

String. HTML tag A.

Usage

get_the_author_link();

Examples

0

#1 Display the post author’s Website URL as a link

The link text will be the author's name, which is specified in the "Display name" field in the profile.

<p>Written by <?php echo get_the_author_link(); ?></p>

We get it:

Written by: <a href="https://{author_site}">James</a>

or

Written by: James

if the author does not have a website listed.

Notes

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

Changelog

Since 3.0.0 Introduced.

get_the_author_link() code WP 6.8.3

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();
	}
}