Using WordPress ‘comment_reply_link’ PHP filter

The comment_reply_link WordPress PHP filter allows you to modify the HTML markup for the comment reply link.

Usage

add_filter('comment_reply_link', 'your_custom_function', 10, 4);

function your_custom_function($link, $args, $comment, $post) {
  // your custom code here
  return $link;
}

Parameters

  • $link (string): The HTML markup for the comment reply link.
  • $args (array): An array of arguments overriding the defaults.
  • $comment (WP_Comment): The object of the comment being replied.
  • $post (WP_Post): The WP_Post object.

More information

See WordPress Developer Resources: comment_reply_link

Examples

Modify the comment reply link text to “Respond to this comment”:

add_filter('comment_reply_link', 'change_reply_link_text', 10, 4);

function change_reply_link_text($link, $args, $comment, $post) {
  $link = preg_replace('/<a(.*?)>(.*?)<\/a>/i', '<a$1>Respond to this comment</a>', $link);
  return $link;
}

Add a custom CSS class called “my-reply-link” to the comment reply link:

add_filter('comment_reply_link', 'add_custom_css_class', 10, 4);

function add_custom_css_class($link, $args, $comment, $post) {
  $link = preg_replace('/<a(.*?)>/i', '<a$1 class="my-reply-link">', $link);
  return $link;
}