函数文档

comment_author_url_link()

💡 云策文档标注

概述

comment_author_url_link() 是一个 WordPress 模板标签,用于直接输出当前评论作者的 URL 链接的 HTML 代码。它基于 get_comment_author_url_link() 函数实现,适用于在主题模板中快速显示评论作者链接。

关键要点

  • 函数直接输出 HTML 链接,无需额外 echo 或 print。
  • 接受四个可选参数:$link_text(链接文本,默认为空)、$before(链接前文本/HTML)、$after(链接后文本/HTML)、$comment(评论 ID 或 WP_Comment 对象,默认为当前评论)。
  • 从 WordPress 4.6.0 版本开始添加了 $comment 参数,允许指定特定评论。
  • 相关函数 get_comment_author_url_link() 用于检索链接而不直接输出。

代码示例

// 默认用法,输出作者 URL 链接
comment_author_url_link();

// 自定义链接文本和样式
comment_author_url_link('Visit Site of Comment Author', '• ', ' •');

注意事项

  • 确保在评论循环内使用,或通过 $comment 参数指定评论,以避免输出错误。
  • 参数 $before 和 $after 可用于添加 HTML 标签或样式,如示例中的项目符号。

📄 原文内容

Displays the HTML link of the URL of the author of the current comment.

Parameters

$link_textstringoptional
Text to display instead of the comment author’s email address. Default empty.
$beforestringoptional
Text or HTML to display before the email link.
Default empty.
$afterstringoptional
Text or HTML to display after the email link.
Default empty.
$commentint|WP_Commentoptional
Comment ID or WP_Comment object.
Default is the current comment.

Source

function comment_author_url_link( $link_text = '', $before = '', $after = '', $comment = 0 ) {
	echo get_comment_author_url_link( $link_text, $before, $after, $comment );
}

Changelog

Version Description
4.6.0 Added the $comment parameter.
0.71 Introduced.

User Contributed Notes