WordPress author comment highlighting

I’ve noticed a few people doing ‘author comment highlighting’ on other blogs, and thought it was kinda neat. How often are you reading through comments on a blog and not realizing that the person commenting is the owner of the blog?

Well, why not highlight your own comments on your own blog so your visitors know it’s you?

Here’s how I added it to this blog:

1) I decided to highlight the comments based on my e-mail address. This means that every comment post that uses my e-mail will be marked as ‘special.’

To do this I used a small snippet of PHP code (new code is bold):

<li id="comment-<?php comment_ID() ?>"<?php if ($comment->comment_author_email == "geoff@deconcept.com") { ?> class="mycomment"<?php } ?>>

2) Edit your stylesheet so your posts are different. Since I added the class mycomment to the comments I make, I added this to my stylesheet:

ol#commentlist li.mycomment {
   background-color: #fbfbfb;
   border: solid 1px #457AA5;
}

3) Make sure nobody can post comments by pretending to be you:

I think everyone should do this on their blog anyway, but here it comes in extra handy. I went into ‘options ->discussion’ in wordpress and added my e-mail address to the list under ‘Comment Moderation.’ This assures that if a comment containing my e-mail address anywhere in the post, the comment will be held for approval by me. So every time I post a comment I’ll have to approve it before it shows up, but this isn’t really a big deal and takes almost no time at all to do.

I’m sure there are ways to improve this and make it better, like checking all of the author e-mail addresses, and possibly giving each author their own unique css class so they can each have their own look, and then packaging all of this up into a WordPress plugin… But I’m much too lazy for that, and since this works fine for my single user blog, I’ll probably just leave it like this.

UPDATE (4-28-05): Just saw this post on the WordPress support blog that updates this for use with WordPress 1.5 and also supports alternate post highlighting as well.

10 thoughts on “WordPress author comment highlighting

  1. This is fabulous, only I can’t tell which snippet of the PHP code is bold. :( I could just open my files and compare, but wanted to let u know. ;)

  2. Really? I put the code within strong tags, maybe your browser doesn’t make them bold? Maybe I’ll just add the style in my stylesheet.

  3. Actually, if I take a closer look, it is bolded, it’s just hard to notice. If I increase the font size in Firefox, then I can make out the bolding. ;)

  4. I’ve seen the ‘author’s comment’ style used on a number of popular blogs and did a quuick Yahoo search and this page was No#1 on the results list, and rightly so. You’ve neatly provided the solution.

    Thanks for your work.

  5. Pingback: La maté por un yogur

  6. I’m using WP 1.5 and a hacked up version of the Kubrick theme. I changed the above code so it works with the alternate highlighting. In the comments.php file replace this line (should be line 29):

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

    …with this line:

    <?php if ($comment->comment_author_email == "simon@simondorfman.com") echo 'mycomment'; else echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">

    Works fine for me. See it in practice here:
    http://simondorfman.com/Games/Spellfire/2005/03/12/to-the-pain-thieves-deck/#comments

  7. This is how I addapted it for two authors :)

    Then of course make your style sheets different.

    <li class="<?php if ($comment->comment_author_email == "email1@email.com") echo 'christopher'; else if ($comment->comment_author_email == "email2@email.com") echo 'christine'; else echo $oddcomment; ?>" id="comment-< ?php comment_ID() ?>"></li>

Comments are closed.