WordPress comment_reply_link() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, comment_reply_link() prints the Reply link for one comment. When a visitor clicks it, the comment form moves under that comment.

It prints the link. It is used in a comment callback for wp_list_comments(). Threaded comments must be on in Settings → Discussion.

Syntax

Merge your own arguments with the ones that WordPress passes to your callback.

WordPress
comment_reply_link( array_merge( $args, array(
  'depth'     => $depth,
  'max_depth' => $args['max_depth'],
) ) );
CallWhat it does
comment_reply_link( $args )Prints a Reply link using the arguments you give.
comment_reply_link( $args, 15 )Prints the Reply link for comment 15.
get_comment_reply_link( $args )Returns the link instead of printing it.

Useful keys in $args are reply_text, reply_to_text, login_text, before, after, depth, and max_depth.

Full declaration
WordPress
comment_reply_link( array $args = array(), int|WP_Comment $comment = null, int|WP_Post $post = null ): void

Parameters

ParameterDescription
$argsOptional. Array of options. Keys include add_below, respond_id, reply_text, reply_to_text, login_text, max_depth, depth, before, and after.
$commentOptional. A comment ID or WP_Comment object. Default is the current comment.
$postOptional. A post ID or WP_Post object. Default is the current post.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the link. It prints nothing if replies are not allowed or the maximum depth is reached.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — In a callback

Print the Reply link inside a custom comment callback.

WordPress
function mytheme_comment( $comment, $args, $depth ) { ?>
  <li id="comment-<?php comment_ID(); ?>">
    <?php comment_text(); ?>
    <?php
    comment_reply_link( array_merge( $args, array(
      'depth'     => $depth,
      'max_depth' => $args['max_depth'],
    ) ) );
    ?>
<?php }

How It Works

  1. WordPress passes $args and $depth to your callback.
  2. array_merge() adds them to the reply link options.
  3. The link carries the comment ID in replytocom.

Example 2 — Custom link text

Change the text of the Reply link.

WordPress
<?php
comment_reply_link( array_merge( $args, array(
  'reply_text' => 'Answer',
  'depth'      => $depth,
  'max_depth'  => $args['max_depth'],
) ) );
?>

How It Works

  1. reply_text sets the visible text.
  2. The other attributes do not change.
  3. Use reply_to_text to change the screen reader label.

Example 3 — Wrap the link

Add a wrapper with before and after.

WordPress
<?php
comment_reply_link( array_merge( $args, array(
  'before'    => '<div class="reply">',
  'after'     => '</div>',
  'depth'     => $depth,
  'max_depth' => $args['max_depth'],
) ) );
?>

How It Works

  1. before prints before the link.
  2. after prints after the link.
  3. If no link is printed, the wrapper is not printed either.

Frequently Asked Questions

It prints a Reply link for one comment so a visitor can answer it.
Threaded comments may be off, the maximum depth may be reached, or you did not pass depth and max_depth.
WordPress prints a Log in to Reply link instead. You can change it with login_text.
The link works without it, but the form moves under the comment only when the comment-reply script is loaded.
Use get_comment_reply_link().

Next: comment_text()

Print the text (body) of the current comment.

comment_text() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful