Customize the Blog Author Comments



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() ?>
</div>

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() ?>
</div>

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 RobertoAlamos.com for providing the PHP code.

Sign-up To The Newsletter And Get A Free eBook


  • Sign-up to the Daily Blog Tips newsletter and you will be able to download the "Make Money Blogging" eBook for free (worth $47).
  • You will also receive tips to improve your blog, strategies to make money and useful resources from around the web.

46 Responses to “Customize the Blog Author Comments”

  1. Daniel on May 3, 2007 7:50 am

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

  2. Roberto Alamos on May 3, 2007 8:13 am

    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:

    if(apply_filters(‘user_id’,
    $comment->user_id) == 1) {

    }

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

  3. rtriharyana on May 3, 2007 8:33 am

    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-">

  4. Cristi on May 3, 2007 8:34 am

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

  5. Daniel on May 3, 2007 8:41 am

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

  6. Enblogopedia on May 3, 2007 9:23 am

    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.

  7. Roberto Alamos on May 3, 2007 10:10 am

    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.

  8. Daniel on May 3, 2007 12:21 pm

    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.

  9. Enblogopedia on May 3, 2007 12:27 pm

    You can create a secret email address just for that purpose.

    And the question will be…why?!! :)

    As you know..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?

  10. Daniel on May 3, 2007 12:56 pm

    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:

    if(apply_filters(‘comment_author_email’,
    $comment->comment_author_email) == ‘yourmail@domain.com’)

  11. Michael Wales on May 3, 2007 1:49 pm

    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:
    http://www.betaflow.com/2007/04/yahoo-purchases-right-media-follows-googles-lead/

  12. Jessie on May 3, 2007 5:29 pm

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

  13. Matt Levenhagen on May 3, 2007 8:45 pm

    This is very cool.. thanks for the tip! :-)

  14. Madhur Kapoor on May 4, 2007 1:10 am

    Thanks for the Nice tutorial Daniel .

  15. Somebaudy on May 4, 2007 1:54 am

    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…)

  16. Daniel on May 4, 2007 2:01 am

    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() ?>

  17. Shankar Ganesh on May 4, 2007 4:15 am

    Hey! Many thanks for the tip!

  18. Nirmal on May 4, 2007 5:54 am

    This is really wonderful tip. Thanks for sharing

  19. Richard on May 5, 2007 2:53 am

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

  20. Daniel on May 5, 2007 3:04 am

    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.

  21. Tim McCormack on May 7, 2007 6:31 pm

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

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

  22. Enblogopedia on May 8, 2007 2:45 am

    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.

  23. Tim McCormack on May 8, 2007 8:06 am

    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.

  24. Daniel on May 9, 2007 3:44 pm

    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.

  25. Enblogopedia on May 10, 2007 10:49 am

    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 :)

  26. Ajay on May 13, 2007 9:35 am

    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 :)

  27. Jason Kotecki on August 28, 2007 8:28 am

    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!

  28. Andy on September 21, 2007 9:29 pm

    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!

  29. Visitor034 on October 17, 2007 2:20 pm

    I have visited your site 529-times

  30. youlong on November 20, 2007 12:28 am

    1111111111111111111

  31. youlong on November 20, 2007 12:29 am
  32. Liane on March 19, 2008 10:29 pm

    Is this code suitable for blogger platform? I can’t seem to find commenttext on my template.

  33. Daniel Scocco on March 20, 2008 4:02 am

    This code if for WordPress.

  34. xxcemil on June 3, 2008 4:10 pm
  35. javascript on June 12, 2008 4:45 pm

    HI i need your help i really want to create my own website/web page but i dont know how to go about doing it so can you please help me out

  36. Bang Kritikus on January 30, 2009 12:48 am

    thanks daniel

Sponsors

Advertise Here Start Making Money Online in 12 Weeks! Get A Keyword Research Report Backlink Build Link Building Services Pay Only When You Rank - RankPay Flex Theme for WordPress

Popular Articles