This is an old topic that has been covered by many other blogs and magazines–to the extreme, but it needs updating. I’m talking about how to highlight comments posted by the author of the article. The tutorials out there only work for one user ID for the whole site. That is a big mistake, as it didn’t allow for scalability — it only works when you are blogging on your own (and with only one account). We have given it an overhaul, and updated the code.
Like the article? Be sure to subscribe to our RSS feed and follow us on Twitter to stay up on recent content.
First, we should take a look at the code from the tutorials which highlight the comment based on the user ID:
.authcomment {
background-color: #B3FFCC !important;
}
<li class=”<?php
if (1 == $comment->user_id)
$oddcomment = “authcomment”;
echo $oddcomment;?>” id=”comment…">
...
</li>
To make it work on sites with multiple writers, we need to to get the ID of the author, then check if the ID of the person posting this comment is the same. If it is, we need to make it stand out. We still use the CSS class for post author comment.
.authcomment {
background-color: #B3FFCC !important;
}
Now, we change the original code at the start of the article with this:
<li class="comment-container
<?php
$authID=get_the_author_meta('ID');
if($authID == $comment->user_id)
$oddcomment = 'authcomment';
echo $oddcomment;
?>" id="comment-<?php comment_ID(); ?>">
...
</li>
And, that’s it! We hope that you find it useful!


Thanks for the post. Just was looking for the same
Great post from you .. Thanks again.
.-= SmashingWebs.com´s last blog ..Top 10 Tutorials to Replace Flash With jQuery =-.
Hi! thank you for the tip!
.-= Sant’ Ennio´s last blog ..Horve 0.3 released! =-.
Nice one Lam. Scalability is often neglected.
Going to implement this code asap!
.-= Duane Kinsey´s last blog ..23 Ways to Run a More Environmentally Sustainable Design Business =-.
It’s better if you put one screeshot also
As someone who’s new to design and is still in the front end of things (ie, I know little PHP), it’d be handy if you could run through what each line does.
I’m currently reading through a jQuery book so I can _kinda_ follow along, but I just don’t understand exactly what’s happening – esp. with the PHP in the class section of the DOM.
I’m not asking you to add to the article, I’m just saying that I’m a n00b to PHP and don’t get what’s going on, even though your solution is something I’d love to know how/why to do on my own site.
.-= Laneth Sffarlenn´s last blog ..View Source – My best friend since 1997 =-.
JUST MARK IT
Thanks Lam.. I am redesigning my blog theme, this tutorial will help me.
Thanks for this article Lam! Nice Stuff!
.-= Comunicarte´s last blog ..Dia do Pai: I Love my Dad… And You? =-.
I just checked your author comments on this blog, an it looks great. I can think of a lot other thing to highlight.
Thanks for this useful tip.
.-= Elas Beauty´s last blog ..Winterschleier adè – Hautunebenheiten behandeln mit Microdermabrasion =-.
For an example instead of a screenshot. My ID is not 1
. I’m a post author
Hey, I’m admin of this blog. This should be my article!!!!!!!
No way …. Sorry
P/S: Just for an example!
Hum… Nice example..
Innovative idea .. Thanks for sharing..
Thank you,Lam! I`m changing my author`s code right now!
.-= Madalin´s last blog ..30 Premium WordPress Themes of February 2010 =-.
Great tip. I’m going to have to try this out on my next wordpress theme.
Really helpful stuff again, have learn’t alot from your posts!
You only edit this Stylesheet for the highlighted Author
.commentlist .bypostauthor {
// Layout für Kommentare des Artikel-Autors
background-color:#CC0000 !important;
}
.-= René´s last blog ..Artikel-Autor in den Kommentaren hervorheben =-.
Simple and effective solution for comment highlighting. Thanks
.-= Omer Greenwald´s last blog ..How to Add jQuery Effects to Your WordPress Blog Without Installing Plugins =-.
thankx for the post,i’m looking this tutorial…
.-= craftdsign´s last blog ..Why is Search Engine Optimization (SEO) Important? =-.
Better way:
If your theme uses the wp_list_comments function to display comments (as all modern themes should), then this is all built-in. Just add your styling rules to “.bypostauthor”, which gets automatically added to the appropriate comments.
.-= Otto´s last blog ..Simple Twitter Connect =-.
We also use the same way in our site…just add styling rules to “.bypostauthor” in your style.css file.
For detail, we also write a tutorial here : http://www.dynamicwp.net/articles-and-tutorials/easy-way-to-highlight-author-comments-with-a-different-background-color/
.-= Eko Setiawan´s last blog ..Sky Light Theme =-.
I’m still learning WordPress. This is great info. Thanks for sharing!
Hey Lam, this is very helpful! i think it is important to separate the author comments from the rest of the bunch to give extra clarification for those who may be unaware (newcomers). keep these type of great articles coming!
.-= Jonathan Anthony´s last blog ..365icon Beat Apple.com in iPhone Google Search! =-.
Hmmm… I think otto (user that posted) gives a much better way… after all wp_list_comments is the new way to display comments. This is a little outdated for 2010.
For anyone who’s interested I’ve created a tutorial here on how to style threaded comments using background images and highlighting any logged-in commenter. It adds the user name to the list of classes churned out by WordPress, and then uses some clever CSS.
I watched a cool way in Uxbooth, the author highlights his comment by using a watermark of the blog on the botton-right side.
Thanks for the snippet
.-= Luis Lopez´s last blog ..10 Sitios para descargar texturas =-.
Thanks for this wonderful tut!
Enjoyed it
.-= CSSReX´s last blog ..25 Best Free Futuristic / Techno Fonts =-.
I’m a real noob, how do I install it? Seriously I have no idea where to put the code?
Help Anyone
.-= ebook reader´s last blog ..Nook Ebook Reader Firmware Update =-.
Thanks for sharing. It will help me.
Thanks for code example!
Thanks. Worked perfect!
.-= College Fashion´s last blog ..How to…Snag That Summer Hottie =-.
Thanks. I’ve been looking for a good solution and this one works even for my Buddypress blog.
bt what i need is plugin! where can i find comment highlight plugin.. Lam?
Thanks for the post. I was just looking for this code.
thanks for the information I am really apprecieated
where should we use this code ?
I can’t find the code which is needed to be edited. Can you please guide me which code exactly I need to replace/edit in order to highlight author comments?