Flash TimelineBlue ColorTriangle PatternOlive ColorWeb 2.0 StripesCoffeeCoffeeSwing DancingWorld War II1st Infantry Division PatchWWII Medical Corps BrassardAmateur (Ham) RadioHand CursorOpen BookCompass RoseSea Scouting, Boy Scouts of AmericaVenturing, Boy Scouts of AmericaEagle Scout, Boy Scouts of AmericaPolice Line Do Not CrossFig. 1US Caliber .30 M1 RiflePortland, Oregon SkylineDNASwing DancingSwing DancingModel RocketryFlickrTwitterLinkedInFacebookHypertext Markup Language (HTML)WordPressPre-Hypertext Processor (PHP)Adobe InDesignAdobe PhotoshopAdobe Photoshop LightroomCamera Viewfinder with Photo

Wordpress: Comment Author Styling, Revisited

I’ve been a bit busy this past few days with a gig creating a Wordpress site for a client. Admittedly, this is the type of gig that I could have gone with a free theme from Wordpress and been done with it, but I don’t have a ton of experience creating themes for Wordpress, so I went at it myself.

There is lots of documentation out there that talks about how to style comments from the post author differently so as to set them apart from other comments on the site. I have read through a lot of stuff and it seems there are three basic ways people have outlined to do this:

  1. Download and use a plugin. It’s super-easy to do, requires no theme modification, etc. It also has the overhead of an entire plugin, when one line of code — in a theme — could work.
  2. Modify the theme with code that matches the commenter email address with the post author email address. Works, but is super-easily spoofed if you allow comments from anyone
  3. Modify the theme with code that checks if the comment author ID is equal to “1″ (or any other number). It’s fine if you only have one author. ever.

So, what if you want the theme to work if there are multiple authors? How about if you had 100 authors? I want to share my solution with you. It checks if the comment author ID is equal to the author ID of the post. Simple. Here’s the code:
user_id == get_the_author_ID()): print 'class="authcomment"'; endif;?>
I put this line of code right into the block-level container for the comment. In my case, it went right into a list tag. It checks to see if the user ID of the current comment is the same as the user id of the current post. If this is true, it prints class=”authcomment”. Then I can easily create some stylesheet information to style this as needed.

Now, my example is a bit on the light side. Many themes also have a variable called $oddcomment that produces class=”alt” if its requirements are met (every other post). To accommodate, my final code ended up looking like this. Yours may have to be done slightly different.

<li id="comment-<?php comment_ID() ?>" class="<?php echo $oddcomment; > <?php if($comment-&gt;user_id == get_the_author_ID()): print 'authcomment'; endif;?>">

If you have any questions about how this works, let me know in the comments.

Did you forget to sign-in or did you want to register?. If you're just stopping by, that's okay too.


You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Leave a New Comment

TDDewey Footer Graphic