函数文档

comment_reply_link()

💡 云策文档标注

概述

comment_reply_link() 函数用于在 WordPress 中输出评论回复链接的 HTML 内容。它直接调用 get_comment_reply_link() 并输出结果,适用于在主题模板中快速显示回复链接。

关键要点

  • 函数直接输出 HTML,无返回值,适合在模板中直接使用。
  • 接受三个可选参数:$args(数组,覆盖默认选项)、$comment(评论对象或 ID,默认为当前评论)、$post(文章对象或 ID,默认为当前文章)。
  • 相关函数 get_comment_reply_link() 用于检索链接 HTML,而 comment_reply_link() 负责输出。
  • 自 WordPress 2.7.0 版本引入,是评论系统的基础功能。

代码示例

comment_reply_link( array(
    'reply_text' => __( 'Responder ↓', 'textdomain' ),
    'depth'      => $depth,
    'max_depth'  => $args['max_depth']
) );

注意事项

  • 可通过 $args 参数自定义回复链接的文本、深度等选项,例如使用 'reply_text' 设置本地化文本。
  • 用户贡献笔记提供了自定义回复链接类名的示例,通过 comment_reply_link 过滤器修改输出 HTML。

📄 原文内容

Displays the HTML content for reply to comment link.

Description

See also

Parameters

$argsarrayoptional
Override default options.

Default:array()

$commentint|WP_Commentoptional
Comment being replied to. Default current comment.

Default:null

$postint|WP_Postoptional
Post ID or WP_Post object the comment is going to be displayed on.
Default current post.

Default:null

Source

function comment_reply_link( $args = array(), $comment = null, $post = null ) {
	echo get_comment_reply_link( $args, $comment, $post );
}

Changelog

Version Description
2.7.0 Introduced.

User Contributed Notes

  1. Skip to note 5 content

    Replace class on reply link using below code.

    function wpdocs_comment_reply_link_class( $class ) {
    	$class = str_replace( "class='comment-reply-link", "class='comment-reply-link your-class-name", $class );
    	return $class;
    }
    
    add_filter( 'comment_reply_link', 'wpdocs_comment_reply_link_class' );