Using WordPress ‘get_comment_reply_link()’ PHP function

The get_comment_reply_link() WordPress PHP function retrieves the HTML content for a reply-to-comment link.

Usage

get_comment_reply_link($args, $comment, $post)

Custom example:

$args = array(
    'reply_text' => 'Respond to this comment',
    'before' => '<div class="reply-link">',
    'after' => '</div>'
);
echo get_comment_reply_link($args);

Parameters

  • $args array (Optional): Override default arguments.
    • add_below string: The first part of the selector used to identify the comment to respond below. Default ‘comment’.
    • respond_id string: The selector identifying the responding comment. 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. Default 0.
    • depth int: The depth of the new comment. Default 0.
    • before string: The text or HTML to add before the reply link.
    • after string: The text or HTML to add after the reply link. Default: array()
  • $comment int|WP_Comment (Optional): Comment being replied to. Default current comment. Default: null
  • $post int|WP_Post (Optional): Post ID or WP_Post object the comment is going to be displayed on. Default current post. Default: null

More information

See WordPress Developer Resources: get_comment_reply_link()

Examples

Customize Reply Text

Change the reply link text to “Respond to this comment.”

$args = array(
    'reply_text' => 'Respond to this comment'
);
echo get_comment_reply_link($args);

Add Custom Wrapper

Add a custom wrapper around the reply link.

$args = array(
    'before' => '<div class="custom-reply-link">',
    'after' => '</div>'
);
echo get_comment_reply_link($args);

Customize Login Text

Change the login text for users who are not logged in.

$args = array(
    'login_text' => 'Sign in to leave a comment'
);
echo get_comment_reply_link($args);

Set Max Depth and Depth

Set the max depth and depth of comment tree.

$args = array(
    'max_depth' => 3,
    'depth' => 1
);
echo get_comment_reply_link($args);

Add Custom ID for Responding Comment

Set a custom ID for the responding comment.

$args = array(
    'respond_id' => 'custom-respond-id'
);
echo get_comment_reply_link($args);