String|false|null. Nothing/false/string. A link to display the comment form, in case of success. False if commenting is closed.
Usage
get_comment_reply_link( $args, $comment, $post );
$args(array)
Parameters that affect the display of the link. See below. Default: presets
$comment(int/WP_Comment)
ID of the comment to reply to. By default, the current comment in the loop.
Starting from version 4.4, you can pass the comment object WP_Comment. Default: null
$post(int/WP_Post)
ID or object of the post to which the comment relates. By default, the current post. Default: null
Arguments for the $args parameter
add_below(string)
The prefix name for the comment container. By default comment, means that the form will move under the container with the attribute id="comment-23" (23 is the ID of the comment we are replying to). Default: 'comment'
respond_id(string)
The value of the id attribute of the comment form container. That is, if respond is specified, then when clicking the link, the block with id="respond" will move (this is the comment form block). Default: 'respond'
reply_text(string)
The text of the link. Default: __('Reply')
login_text(string)
The text of the link that is shown when you need to log in to leave a comment. Default: __('Log in to Reply')
depth(int)
The depth of comments for which the link will be shown. For threaded comments. If you specify, for example, 3, then for a comment with a nesting depth of 4, the link will no longer be displayed. Default: 0
before(string)
Text or html to add before the link.
after(string)
Text or html to add after the link. Default: array()
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.9.1