As I was working through the various files involved in my WordPress Desk Mess Mirrored theme I discovered I did not like the original comment author CSS class assignment code.

The original code was as follows:

<?php foreach ($comments as $comment) : ?>
  <div class="<?php if ($comment->comment_author_email == "") echo 'administrator'; else echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>">

It did not thrill me with the choice of using the author’s email address. As far as I see it this could possibly lead to misrepresented comments or replies, if the blog owner was not careful with their contact information and their comment moderation settings.

I started with the idea that there must be a way to check the comment author and compare to the registered users list of the blog. This started my searches and brought me to this codex article: with the following code reference:

<cite<?php if ($comment->user_id == '1') echo ' class="admin"'; ?>>
  <?php comment_author() ?>

Which I expanded upon to this:

<?php foreach ($comments as $comment) : ?>
  <div class="<?php if ($comment->user_id == '1') echo 'administrator';
    /* elseif ($comment->user_id == '2') echo 'administrator'; */
    /* add additional user_id following above example, echo the 'CSS element' you want to use for styling */
    <?php endif; ?>

This snippet of code writes the class administrator for the user_id #1 (generally the blog owner) and can then be further modified for each user_id as appropriate, changing the class or not as the design requires.

To find an individual user_id, go to your blog’s Dashboard; under Users, click on Authors & Users. Click on the Username (to edit); now in the address bar you will see a URL address starting with: http://your_blog_url/wp-admin/user-edit.php?user_id=x… , where x (a number) is the user_id for that particular Username.