Using WordPress ‘comment_reply_link_args’ PHP filter

The comment_reply_link_args WordPress PHP filter allows you to modify the comment reply link arguments.

Usage

add_filter('comment_reply_link_args', 'my_custom_comment_reply_link_args', 10, 3);

function my_custom_comment_reply_link_args($args, $comment, $post) {
    // Your custom code here
    return $args;
}

Parameters

  • $args (array): Comment reply link arguments. See get_comment_reply_link() for more information on accepted arguments.
  • $comment (WP_Comment): The object of the comment being replied to.
  • $post (WP_Post): The WP_Post object.

More information

See WordPress Developer Resources: comment_reply_link_args

Examples

Change the reply text

Change the reply link text to “Respond”.

add_filter('comment_reply_link_args', 'change_reply_text', 10, 3);

function change_reply_text($args, $comment, $post) {
    $args['reply_text'] = 'Respond';
    return $args;
}

Add a custom CSS class to the reply link.

add_filter('comment_reply_link_args', 'add_custom_class', 10, 3);

function add_custom_class($args, $comment, $post) {
    $args['class'] = 'my-custom-class';
    return $args;
}

Modify the login text

Change the login text to “Please sign in to reply”.

add_filter('comment_reply_link_args', 'modify_login_text', 10, 3);

function modify_login_text($args, $comment, $post) {
    $args['login_text'] = 'Please sign in to reply';
    return $args;
}

Add custom HTML before and after the reply link.

add_filter('comment_reply_link_args', 'change_html_before_and_after', 10, 3);

function change_html_before_and_after($args, $comment, $post) {
    $args['before'] = '<div class="custom-before">';
    $args['after'] = '</div>';
    return $args;
}

Set a custom max depth for comment replies

Change the max depth of the comment tree to 5.

add_filter('comment_reply_link_args', 'set_custom_max_depth', 10, 3);

function set_custom_max_depth($args, $comment, $post) {
    $args['max_depth'] = 5;
    return $args;
}