Customize the Blog Author Comments

Daniel Scocco

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.

Start Your Free Trial Today!

Browse all articles on the WordPress category or check the recommended articles for you below:

46 Responses to “Customize the Blog Author Comments”

  • Bang Kritikus

    thanks daniel

  • javascript

    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

  • xxcemil

    about css parameters

  • Daniel Scocco

    This code if for WordPress.

  • Liane

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

  • youlong


Comments are closed.