How to change the “Reply” text in the comments listing and add a custom css class to the “Reply” link?

If you open the comments.php template file and look at the source code you will find that “wp_list_comments” function is used to display the comments listing. To change the “Reply” text your can pass “reply_text” parameter to “wp_list_comments” function.

Similarly to customize the comments listing frontend design you can pass a callback function as parameter to “wp_list_comments” function as shown below.


<?php

wp_list_comments(array('reply_text'=>'Reply &raquo;', 'callback'=>'theme_comment'));

?>

The callback function can then be defined in the functions.php file. Refer to [http://codex.wordpress.org/Function_Reference/wp_list_comments] for the complete list of parameters that can be passed to “wp_list_comments” function.


<?php

function theme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>

<div class="comment-listing" id="comment-<?php comment_ID() ?>">
<div class="gravatar">
<?php echo get_avatar( $comment, 40 ); ?>
</div>

<?php
if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>

<?php edit_comment_link('edit','&nbsp;',''); ?>

<div class="feedback">
<h3><?php comment_author_link() ?></h3>
<span><?php comment_date('F d, Y') ?></span>
<?php comment_text() ?>
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>

<?php
}
?>

The comments reply link has a class “comment-reply-link” by default. If we need to modify this class name or add a new class the we will have to modify the function “get_comment_reply_link” located in file {{WORDPRESS_ROOT}}/wp-includes/comment-template.php. We should avoid modifying the core file, so the solution is to add a wrapper element to the link by passing the “before” and “after” parameters to the function “comment_reply_link” and add our custom class to it.


<?php

comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => '<div class="my-custom-class">', 'after'
=> '</div>')))

?>

Check the [“http://codex.wordpress.org/Function_Reference/comment_reply_link“] for detailed list of parameters.

Hope this helps!

Leave a Comment

Back to top