Highlight admin’s comments easily

Published: On Tuesday, November 13, 2007

I've got know about a plugin today, that should help us with with highlighting comments written by the blog's author. „Why the heck should somebody use a plugin for such a simple operation?“ – I asked myself in the first moment. Yes, the plugin provides a few possibilities that can be called as non-trivial but people should not forget that this basic issue can be solved extremely easily and – without any plug-in. In fact, I'm wondering that this capability is not included in default theme, actually I'm not wondering, because Kubrick still misses much more than that.

How to…?

Let's open comments template (mostly comments.php) and find the code of a single comment, in default template it begins with…

<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">

Oh yes, we need to add a class conditionally, and default template does not presuppose something like this. Most simple will be to remove echo $oddcomment; code and instead of that paste this condition:

if ($comment->user_id) echo ' class="my_comment" ';

…which means „if this comment was written by a registered & logged user, than assign a class to it“. Then you need only to style the class, so you would probably add to the style.css another definition like this one:

.my_comment {background-color:#f2f2f2}

Think about that

Think about that. Highlighting admin's comments will be surely more helpful then highlighting odd/even comments. I don't know how about you, but I

  1. hate highlighted odd comments via different background color
  2. (because I think it's usually unnecessary)
  3. because I consider this to be an established way of emphasizing author's comments
  4. so I am often confused.

Comments

  1. 1.  emmanuel wrote: On March 6., 2008 comment number 1

    Thank you very much, this tip is very usefull, and the method you give here is the simplest I found on the web. Go on

  2. 2.  adspedia.ro wrote: On June 3., 2008 comment number 2

    I tried doing the steps above and it does not work :(

  3. 3.  Kahi [author] wrote: On June 3., 2008 comment number 3

    ↪ adspedia.ro look in the final source code if your own (admin's) comments have correctly assigned class="my_comment". If not, mistake must be in the first step.

  4. 4.  Richh wrote: On January 7., 2009 comment number 4

    Just so you know, this plug-in won't be needed if you're using WP 2.7 or above – at least if you're using one of the default themes or one that the theme author has updated properly to take into account WP 2.7's new comment features. The latest versions of WorPress automatically add different classes to the commetns depending on the role of who posts them – so an author has class=„bypostau­thor“ for example. This makes it real easy to style author/admin comments and make them stand out from the rest!

  5. 5.  Kahi [author] wrote: On January 7., 2009 comment number 5

    Richh, thank you for your comment. I haven't checked changes in 2.7 templates yet. And I can't say I like the way they did it.

  6. 6.  John wrote: On February 20., 2010 comment number 6

    Can you tell me how to do this with the following comments.php?
    Thanks

    [the code was removed by admin]

  7. 7.  John wrote: On February 20., 2010 comment number 7

    OK, that's totally not what I just pasted there. Sorry. I think I need to modify <?php wp_list_comments but I'm not sure how

  8. 8.  Kahi [author] wrote: On February 20., 2010 comment number 8

    ↪ John Since WP 2.9 (or maybe even sooner) there are often automatically some of these classes added to comments:

    • byuser
    • comment-author-admin
    • bypostauthor

    So the only thing you need to do is to style those comments: e.g. with .bypostauthor {background-color:#f2f2f2}. I probably need to update the article, thanks.

  9. 9.  Daniel wrote: On October 2., 2010 comment number 9

    best fix around. well done

I quit working with WordPress, comments are closed. My plugins will not be updated any more – at least not by me. Feel free to modify my source codes though… Also I am not able to provide support, sorry. –Kahi