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

5 Answers 5

up vote 3 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

Also something to double check (as I overlooked this for about half an hour)...

Make sure under: Settings > Discussion

This checkbox is checked:

Enable threaded (nested) comments levels deep

Otherwise the reply button will not show up at all

share|improve this answer

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

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

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

protected by toscho Nov 19 at 11:57

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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