Skip to main content

WordPress: Author comment highlighting

·284 words·2 mins· ·
General Everything Wordpress Web Development Features
Ariejan de Vroom
Author
Ariejan de Vroom
Jack of all Trades, Professional Software Craftsman

I’ve seen it lots of times before, but I just added it to Ariejan.net (and the next release of the iAriejan theme). Sometimes there are lots of comments and it’s nice for visitors to see what the official reaction of the blog author is.

Since I haven’t really looked into a plugin or anything, this is just a very simple theme hack.

You can apply it to your current theme with almost no effort at all.

Open up your comments.php file in your themes directory. And look for the following code:

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

and replace it with

<li class="<?php if ( $comment->comment_author_email == get_the_author_email() ) echo 'authorcomment'; else echo $oddcomment; ?>" id="comment-< ?php comment_ID() ?>" id="comment-< ?php comment_ID() ?>">

What this will do is match the e-mail address of the poster with the e-mail address of the post author. This is in some way spoofable, as users may be able to post a comment with your e-mail address on it.

If you posted the comment an extra CSS class named ‘authorcomment’ is added. So add the following to your style.css file. (You may change this to suit your own taste of course):

.authorcomment {
    background-color: #363636;
    border: 1px solid #969696;
}

To prevent this you can add your e-mail address (the one you use with your WP account) to Options -> Discussion -> Comment Moderation. This will keep any post that contains your email address back for moderation by you. This is the only fool-proof method I know right now to keep people from spoofing. There might be some other hacks for this, but I haven’t had time to think about that yet.

Related

SVN: How to fix bugs properly
·899 words·5 mins
General Everything Web Development Features Subversion
SVN: How to release software properly
·857 words·5 mins
General Everything Web Development Features Subversion
Tagging in ajax_scaffold
·468 words·3 mins
General Everything Web Development RubyOnRails Features