xw48hf
xw48hf

Reputation: 447

How to add extra css class to comment-reply-link generated by comment_reply_link function ?

So, here is the problem in adding css class in WordPress comment reply section

comment_reply_link function adds css class comment-reply-link in reply button. Is there as way I can add new css class to comment-reply-link ?

I know that I can do that using jquery but is there any way of doing so without using jquery ?

Upvotes: 4

Views: 5104

Answers (3)

stephendwolff
stephendwolff

Reputation: 1712

Combining a couple of the other answers

function custom_comment_reply_link($content) {
    $extra_classes = 'button button--small button--white';
    return preg_replace( '/comment-reply-link/', 'comment-reply-link ' . $extra_classes, $content);
}

add_filter('comment_reply_link', 'custom_comment_reply_link', 99);

This adds the value of $extra_classes to all reply links 'class' attribute.

Upvotes: 2

Bamz Springfield
Bamz Springfield

Reputation: 56

With this, I add class to comment-reply-link

<?php 
    $myclass = 'icon-share-alt';
    echo preg_replace( '/comment-reply-link/', 'comment-reply-link ' . $myclass, 
        get_comment_reply_link(array_merge( $args, array(
            'add_below' => $add_below, 
            'depth' => $depth, 
            'max_depth' => $args['max_depth']))), 1 ); 
?>

Screenshot:

Upvotes: 4

lefoy
lefoy

Reputation: 1178

You can add a filter to the comment_reply_link function.

function comment_reply_link_filter($content){
    return '<div class="yourclass">' . $content . '</div>';
}
add_filter('comment_reply_link', 'comment_reply_link_filter', 99);

I know it's not directly on the element, but you can now style the element with .yourclass > .comment-reply-link.

Upvotes: 1

Related Questions