get_the_author_link

函式
get_the_author_link ( No parameters )
返回值
  • (string|null) An HTML link if the author's url exist in user meta, else the result of get_the_author().
定義位置
相關方法
get_the_author_loginget_the_author_idget_author_linkthe_author_linkget_the_author_aim
引入
3.0.0
棄用
-

get_the_author_link: 這個函式檢索到文章作者的檔案頁的連結。它不接受任何引數,返回一個HTML格式的連結。

檢索作者的連結或作者的名字。

如果作者設定了主頁,返回一個HTML連結,否則只返回作者的名字。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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’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();
}
}
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’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(); } }
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’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();
	}
}

常見問題

FAQs
檢視更多 >