Customize the Blog Author Comments


background image

Would you like to customize the comments that you leave on your own blog? This feature could add a personal touch to the comment section, and it might also help the readers to identify your comments and to follow the conversation. Below you will find a step by step guide to accomplishing this:

Locate the comment class attribute on the Stylesheet

The first thing you need to do is to locate the class attribute on your Stylesheet (usually style.css) that is governing the text field on your comments. You are looking for something like this:

.commenttext {
clear: both;
padding: 20px 10px 20px 10px;
width: 400px;
background-color: #FFFFFF;

Create a second class for the blog author

Normal comments will use that class (notice that “commenttext” is just an example, your class attritube might have another name). Now you need to create a second class, the one that will be used by the comments of the blog author, customizing it. If you just want to change the background color, for instance, the second class will look like this:

.commenttext-author {
clear: both;
padding: 20px 10px 20px 10px;
width: 400px;
background-color: #F7F7F7;

You can also add a badge to your comments by using a background image.

Locate the comment loop

Once you have the two classes ready on your Stylesheet you will need to open the comments.php file and locate where the comment loop starts, usually with this line:

<?php foreach ($comments as $comment) : ?>

Inside the loop you will need to find the code that is calling the class that styles the comments:

<div class="commenttext">
<?php comment_text() ?>

Insert a PHP conditional clause

As you can see from the code above the comment function is calling the “commenttext” class for every comment. We need remove that first line and insert a conditional clause that will call the “commenttext-author” class if a certain parameter is found (this parameter will be the author user ID, which is usually 1 or 2 depending on your WordPress version), and the normal “commenttext” class if the parameter is not there:

<?php $class = 'commenttext'; if(apply_filters(’user_id’,
$comment->user_id) == 1) { $class =
'commenttext-author'; } ?>
<div class="<?=$class?>">
<?php comment_text() ?>

Once you insert the code above (remember that the classes mentioned are just examples, you might need to edit the code with your own class names) the comment function will call the “commenttext-author” class every time someone posts a comment with the author user ID. All other comments will keep using the normal “commenttext” class.

I would like to thank Roberto from for providing the PHP code.

Browse all articles on the WordPress category

46 Responses to “Customize the Blog Author Comments”

  • youlong


  • Visitor034

    I have visited your site 529-times

  • Andy

    I was just thinking about this too and found you on google. The .alt is easily done for every other post to change color but I was looking for the admin/author to change. Adds that peronsal touch, Thankyou!

  • Jason Kotecki

    I have two authors on my blog and I’d like to highlight each of them with a different style than the normal comments. You mentioned that you’d need to insert more clauses to cover all the authors. What would that extra clause look like? I’m not very well versed in PHP but was able to follow your directions above just fine for a single author.

    Any help would be appreciated!

  • Ajay

    This is indeed a much better hack than the one I got on my blog. Mines restricted to a single email address, but I’m going to give this a shot. Thanks 🙂

  • Enblogopedia

    what about a guest author Daniel?
    I think mixing the two conditions (Daniel’s one and Tim’s) would be a great touch. First check if it was wrote by the blog owner, if yes give it a unique look, if not give it another look but also not like the standard one 🙂

  • Daniel

    Tim, if the blog has only one author both cases you mentioned are really the same.

    If you have a multi-author blog you would need to insert more if clauses to cover all the authors.

  • Tim McCormack

    Ah! I suppose I’ve misunderstood the intent here. There are several possibilities here:
    * Highlight the comments by the author of the post.
    * Highlight the comments by the owner of the blog.

    I assumed you were talking about the former. The latter might be trickier to do in a robust manner.

  • Enblogopedia

    Well Tim McCormack, if the post_author and the user_id refer to the same value then I think yes, but this way you are not customizing the blog owner comment, only the author(even if it`s a guest post) will be customized.

  • Tim McCormack

    Erm… why not just check if the commenter and the poster have the same userID?

    $comment->user_id === $post->post_author

  • Daniel

    Richard, that is true. Additionally this feature will also make sure that readers know that you are active on the discussion.

    Is very discouraging when you post a comment on a blog only to find no one is reading or replying to it.

  • Richard

    Thanks, I think comments are the best way for creating a regular readership base. Anything to differentiate yourself from other blogs, definitely helps.

  • Nirmal

    This is really wonderful tip. Thanks for sharing

  • Shankar Ganesh

    Hey! Many thanks for the tip!

  • Daniel

    Somebaudy, the many classes on your comment section are probably governing different parts, like the style of the author name, the date, etc.

    You need to find the class that is styling the text of the comments.

    It will probably come right before this line:
    <?php comment_text() ?>

  • Somebaudy

    has anyone managed to do that on a theme where the CSS for the comment is split between many class ? (K2 I’m loooking on your direction…)

  • Madhur Kapoor

    Thanks for the Nice tutorial Daniel .

  • Matt Levenhagen

    This is very cool.. thanks for the tip! 🙂

  • Jessie

    Thank you thank you for this! I was just thinking of this the other day!

  • Michael Wales

    I use this on my blog as well – it’s a great way to let reader know you are involved in the discussion as well. You can see an example here:

  • Daniel

    Alright the post was updated, I agree that since readers will be using the code it is better to make them use the most effective version.

    If someone is getting trouble with the User ID you can still try the email version of the IF condition:

    $comment->comment_author_email) == ‘’)

  • Enblogopedia

    You can create a secret email address just for that purpose.
    And the question will be…why?!! 🙂

    As you are writing tips for the readers so you need to provide them the best solution as there`ll be a lot of webmasters sharing their “admin” e-mails, right?

  • Daniel

    Englobopedia, I agree that it is safer to use the user ID as the parameter.

    Using the email should not be a problem though. First you don’t need to use your own email address, that is the one you send email to readers with. You can create a secret email address just for that purpose.

    Second, I don’t think there will be someone tryint to “guess” your email address just to post a comment with your customization hehe.

    But again, you and Roberto are right, if you want to have 100% security over this go with the User ID.

  • Roberto Alamos

    That’s absolutely true Enblogopedia. Any user can try to guess the correct email and appear as he’s one of the blog’s authors.

    To prevent that you should only use the user_id in your condition.

  • Enblogopedia

    Roberto, that would be another good option also, thanks for sharing.
    I don’t think it`s another option, actually I don’t think that using the e-mail address is a good idea as it`s not a primary key(i.e. others can take the same value which is here the same e-mail!)
    So the user ID would be the best choice.

  • Daniel

    Roberto, that would be another good option also, thanks for sharing.

  • Cristi

    Great tip, I’m adding this to my blog right now! I’ll let you know how it ends up 🙂

  • rtriharyana

    if u are using a single user (your is admin) for your blog, i think u can apply this code:

    comment_author == get_the_author()) echo ‘comment-list-own’; else echo $oddcomment; ?>” id=”comment-“>

  • Roberto Alamos

    It is worth to mention that you can check if the comment comes from a blog author by using his/her user id (a unique number assigned to every user of your blog) this way:

    $comment->user_id) == 1) {


    You can be user 1 or 2 or N, it depends on your specific wordpress installation.

  • Daniel

    By the way you can see the result of this on my comments, I added a “Daily Blog Tips” badge to all of them.

Comments are closed.