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.

Basically what I want is to have all comments posted by admins with different background color than the rest, so they're easily distinguishable.

I wasn't able to find any plugin that would do this though, and hacking it into the theme doesn't look very clean.

Any suggestions?

share|improve this question
    
do the admin comments have a unique css class? if yes, then all you need is some adaptation to style.css; if you don't know, please post a link to your site. –  Michael Sep 17 '11 at 13:07
add comment

2 Answers 2

up vote 2 down vote accepted

By default WordPress already adds user/admin/post author specific CSS to comments with the following three elements.

#byuser
#comment-author-admin
.bypostauthor

So you can just add something like #comment-author-admin {background-color;blue;} to your stylesheet.

share|improve this answer
add comment

Assuming that your Theme:

  1. Uses the default comment-list markup, via wp_list_comments(), or
  2. Manually applies the <?php comment_class(); ?> template tag appropriately

...then all you need to do in order to style author comments is to target the CSS class .bypostauthor.

So, if, in your case, "author" = "admin", then you're all set.

However, if your site has multiple authors, and/or multiple admins, then that won't be sufficient.

Fortunately, the comment_class() template tag can accept an argument, used to pass additional classes (it is also passed through the comment_class filter, but that is more difficult to use in this case).

So, try something like this:

$additional_comment_classes = '';

if ( user_can( $comment->user_id, 'administrator' ) ) {
    $additional_comment_classes = ' byadmin';
}

Then, when you call <?php comment_class(); ?>, call it as <?php comment_class( $additional_comment_classes ); ?>

Note: you'll need to be using a callback to <?php wp_list_comments(); ?> in order to modify comment_class() in this manner. If you don't want to go that route, then you'll need to add the class via the comment_class filter.

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.