Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Under each comment there is a link called 'Reply'. I want to add a class to this link. It's default class is comment-reply-link. How can I do so? I am creating my own theme and I don't want to manually edit files inside the wp-includes directory.

share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

In your comments.php template file use wp_list_comments and set the parameter callback to your defined function that will generate the template. Inside the function you can style the comment reply link.

wp_list_comments codex
Further reading on comment display

share|improve this answer
    
I am using the callback already. But the callback uses comment_reply_link which doesn't appear to offer a facility for modifying classes. –  mrtsherman Mar 22 '11 at 22:43
    
@mrtsherman - In that case because I also cannot find a way to added another class. You can enclose the comment_reply_link with a <span> or <div> with a class and address the link as .class a. –  imHavoc Mar 22 '11 at 22:50
    
Thank-you for the links. I see under the further reading section them using add_filter to add CSS classes. I understand the syntax of the function, but how I can hook into it for my use case I have no idea. What $tag would I use? –  mrtsherman Mar 22 '11 at 22:51
    
thank-you for the idea. Unfortunately I am really trying to add the class to the actual link. This has to do with using a stylesheet hosted from another server and this Wordpress theme is extending their templates. If nobody else can come up with a better solution I will mark this as best answer. –  mrtsherman Mar 22 '11 at 22:53
    
I ended up using comment_form and the comment_notes_after parameter to add my own button. I hid the default button using CSS and then click it using javascript. Ugly I know, but WP seems to have made it very difficult to fundamentally change things. –  mrtsherman Mar 23 '11 at 22:05
add comment

I know this is quite an old post and maybe this could help someone.

You can replace the class of an element using add_filter();

Here's an example:

// filter to replace class on reply link

//           class name             function name
add_filter('comment_reply_link', 'replace_reply_link_class');


function replace_reply_link_class($class){
    $class = str_replace("class='comment-reply-link", "class='reply", $class);
    return $class;
}

With this you should be able to replace the class in your themes.

I hope this can be of any help for someone :)

share|improve this answer
1  
A regex might be better in case there are two filters on that hook. –  toscho May 15 '13 at 21:08
add comment

Quite old post, but while searching I came here, maybe someone else will find it useful.

The only solution I found is to completely rebuilt the button that comment_reply_link returns.

I first made two vars reconstructing href and onclick attributes for the reply button:

$reply_href = wp_make_link_relative(
    get_permalink( $comment->comment_post_ID ) 
    ) 
    . '?replytocom=' . $comment->comment_ID . '#respond';

$reply_onclick = 'return addComment.moveForm(&quot;comment-' 
    . $comment->comment_ID 
    . '&quot;, &quot;' 
    . $comment->comment_ID 
    . '&quot;, &quot;respond&quot;, &quot;' 
    . $comment->comment_post_ID 
    . '&quot;)';

And then output the whole reply block, adding your custom classes:

<div class="reply">
    <a class="comment-reply-link custom-class" href="<?php 
        echo $reply_href; 
        ?>" onclick="<?php 
        echo $reply_onclick; 
        ?>"><?php 
        _e('Reply', 'yourthemename'); 
    ?></a>
</div>
share|improve this answer
add comment

This might not be an elegant solution but it gets the job done. Do it with jQuery. Basically find the element and add the class you need. WordPress totally didn't make this easy to customize:

jQuery('a#comment-reply-link').addClass('mycustomcssclass');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.