comment_author_link()
云策文档标注
概述
comment_author_link() 是一个 WordPress 函数,用于输出当前评论作者的 HTML 链接。它基于 get_comment_author_link() 实现,主要用于在主题或插件中显示评论作者的可点击链接。
关键要点
- 函数作用:输出评论作者的 HTML 链接,包含作者名称和 URL。
- 参数:$comment_id(可选),可以是评论 ID 或 WP_Comment 对象,默认为当前评论。
- 返回值:无返回值,直接输出 HTML 链接。
- 相关函数:get_comment_author_link() 用于检索链接而不输出。
- 变更历史:从 4.4.0 版本开始,$comment_id 参数支持 WP_Comment 对象。
注意事项
- 输出示例:链接格式通常为 <a href="https://example.com" rel="external nofollow ugc" class="url">Author Name</a>。
- 如果仅需获取评论作者的 URL,应使用 comment_author_url() 函数。
原文内容
Displays the HTML link to the URL of the author of the current comment.
Parameters
$comment_idint|WP_Commentoptional-
WP_Comment or the ID of the comment for which to print the author’s link.
Default current comment.
Source
function comment_author_link( $comment_id = 0 ) {
echo get_comment_author_link( $comment_id );
}
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Added the ability for $comment_id to also accept a WP_Comment object. |
| 0.71 | Introduced. |
Skip to note 2 content
Muhammad Ayoub
This will print author’s link with anchor tag.
output will:
[html]
<a href="https://example.com"; rel=”external nofollow ugc” class=”url”>Author Name
[/html]