WordPress函数:get_the_author_link 获取作者的链接

江河/ 2023年04月30日/ WordPress/ 浏览 641

函数原型:


get_the_author_link(): string|null


如果作者设置了主页,则返回一个HTML链接,否则只返回作者的姓名。


函数源码:


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

		return apply_filters( 'the_author_link', $link, $author_url, $authordata );
	} else {
		return get_the_author();
	}
}


包含钩子:


apply_filters( 'the_author_link', string $link, string $author_url, WP_User $authordata )


使用举例:


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


此示例将作者的网站URL显示为链接,链接的文本为作者的配置文件显示名称。在本例中,作者的显示名称是James Smith。


结果为:


<p>Written by: <a href="http://example.com" rel="nofollow">James Smith</a></p>


发表评论

暂无评论,抢个沙发...

客服 工单