String|false|null. Link to show comment form, if successful. False, if comments are closed.
Usage
get_comment_reply_link( $args, $comment, $post );
$args(array)
Override default arguments.
Default: array()
add_below(string)
The first part of the selector used to identify the comment to respond below. The resulting value is passed as the first parameter to addComment.moveForm(), concatenated as $add_below-$comment->comment_ID. Default: 'comment'
respond_id(string)
The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(), and appended to the link URL as a hash value. Default: 'respond'
reply_text(string)
The text of the Reply link. Default: 'Reply'
login_text(string)
The text of the link to reply if logged out. Default: 'Log in to Reply'
max_depth(int)
The max depth of the comment tree.
depth(int)
The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth' option set in Settings > Discussion.
before(string)
The text or HTML to add before the reply link. Default: ''
after(string)
The text or HTML to add after the reply link. Default: ''
Let's display a link to reply to a comment of maximum nesting level - 5, and change the link text to "reply to comment":
$link = get_comment_reply_link( [
'reply_text' => "reply to comment",
'respond_id' => 'comment',
'depth' => 5,
'max_depth' => 10,
], 2881, 631 );
// here we can process the link before it is displayed on the screen
//$link = str_replace( 'foo', 'bar', $link );
echo $link;
Outputs this html code:
<a
rel='nofollow'
class='comment-reply-link'
href='/function/comment_reply_link?replytocom=2881#comment'
onclick='return addComment.moveForm( "comment-2881", "2881", "comment", "631" )'
aria-label='Comment on Vladimir's post'
>
reply to comment
</a>
Changelog
Since 2.7.0
Introduced.
Since 4.4.0
Added the ability for $comment to also accept a WP_Comment object.
get_comment_reply_link() get comment reply link code WP 6.1.1