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?
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.Assuming that your Theme:
wp_list_comments()
, or<?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 thecomment_class
filter, but that is more difficult to use in this case).So, try something like this:
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 modifycomment_class()
in this manner. If you don’t want to go that route, then you’ll need to add the class via thecomment_class
filter.Open your style.css on your template folder and add this:
Now open your comments.php and find code that should look something like this:
and replace it with this code: