Recently we showed youΒ how to style the WordPress comment form, and we thought it would be incomplete if we did not write about styling WordPress comments layout. In the past, we have discussed that there areΒ default WordPress generated CSS classes and IDsΒ to help make it easier for theme designers to style their templates. In this article, we will be using those default classes to show you how to style your WordPress comments layout and some of the cool things you can do with it.
For the sake of this example, We will be modifying the default Twenty Twelve WordPress theme in this article. Note: This article is for beginning theme designers and DIY users who have fair understanding of HTML and CSS.
Default WordPress Comments Classes
By default WordPress generates these classes for elements in the comments template:
How to Find Which CSS Classes You Need to Edit
Before we move on to styling WordPress comments layout, a little tip for our new users. Google Chrome and Mozilla Firefox web browsers come with a handy tool that you can use to improve your WordPress theme development skills. The tool is calledΒ Inspect Element. Simply take your mouse to an element on a web page, right click and choose inspect element. Your browser window will split into two rows and in the lower window you will see the source code of that element. Also in the lower window, you will be able to see CSS elements and how they are styled. You can even edit the CSS in there for testing purposes. Itβs important to remember, anything you change using the Inspect Element is only visible to you. The moment you refresh the page, those changes will disappear. To make the changes permanent, you have to use your style.css file or other appropriate files in your themes.
Adding Odd and Even Background Colors for Comments
Having a different background color for odd and even comments is a design trend that has been around for some years now. It helps the readability specially if you have a lot of comments. It also looks really good with certain theme colors which is why many designers want to utilize this functionality. To help designers achieve this goal, WordPress adds an odd and even class to each comment respectively.
You can easily add the odd/even styling for comments in your themeβs style.css by pasting the following code.
background-color:#ccddf2;
}
.commentlist .odd .comment {
background-color:#CCCCCC;
}
The result would look something like this:
Styling Comment Author and Meta Information
WordPress also adds classes to elements displayed in each comment header. This allows theme designers to customize the display of author information and other comment meta such as comment date and time. Here is a sample code to paste in your themeβs style.css file to style these elements differently. In this example we have added background color to comment meta along with some spacing.
Β Β Β Β margin: 0 0 48px;
Β Β Β Β overflow: hidden;
Β Β Β Β position: relative;
Β Β Β Β background-color:#55737D;
Β Β Β Β color:#FFFFFF;
Β Β Β Β padding: 10px;
}
This is how it should look like:
Styling Post Author Comments Differently
In the above example, you can see that the theme is usingΒ twentytwelve_commentΒ as the callback function. If a callback function is specified, then the most probable location to find this function is in your themeβs functions.php file.
In this example we are changing this function to display Editor instead of Post Author. To do that we have modified the comment callback function like this:
We are also going to modify the way it looks by adding the following in our themeβs style.css file like this:
Β Β Β Β color: #21759b;
Β Β Β Β background-color: #f8f0cb;
Β Β Β Β background-image: none;
Β Β Β Β border: 1px solid #f8f0cb;
Β Β Β Β border-radius: 3px;
Β Β Β Β box-shadow: none;
Β Β Β Β padding: 3px;
Β Β Β Β font-weight:bold;
}
This is how it would look like:
Styling Comment Reply Link in WordPress Comments
Most WordPress themes have a reply link below each comment. This functionality is only displayed if you have threaded comments enabled. To enable threaded comments, go to your WordPress admin (Settings Β» Discussion). Look at the section where it says other comment settings, and check the box for enable threaded (nested) comments.
The default CSS classes generated by WordPress for the reply link areΒ replyΒ andΒ comment-reply-link. We will be using those classes to modify the reply link and turn into a CSS button.
This is how it would look like:
Styling Comment Edit Button
In most WordPress themes, logged in users with the capability to edit comments can see a comment edit link below each comment. Here is a little CSS that uses the default classΒ comment-edit-linkΒ to modify the appearance of the link.
Β Β Β Β float:left;
Β Β Β Β margin:0 0 10px 10px;
Β Β Β Β text-align:center;
Β Β Β Β background-color: #55737D;
Β Β Β Β border:1px solid #55737D;
Β Β Β Β border-radius:3px;
Β Β Β Β padding:3px;
Β Β Β Β width:50px;
Β Β Β Β box-shadow: 1px 1px 2px 2px #4f4f4f;
}
Here is how it would look like:
Styling Cancel Comment Reply Link
In most good WordPress themes, clicking on the Reply link opens up the comment form just below the comment you are replying to with a link to cancel comment reply. Lets modify this cancel comment reply link by using the default CSS IDΒ cancel-comment-reply.
Β Β Β Β text-align:center;
Β Β Β Β background-color: #55737D;
Β Β Β Β border:1px solid #55737D;
Β Β Β Β border-radius:3px;
Β Β Β Β padding:3px;
Β Β Β Β width:50px;
Β Β Β Β color:#FFFFFF;
Β Β Β Β box-shadow: 1px 1px 2px 2px #4f4f4f;
Β Β Β Β text-decoration:none;
}
Here is how it would look like:
Styling the WordPress Comment Form
Usable, aesthetically pleasant and stylish comment forms encourage users to leave a comment on your blog. Earlier we have written a detailed article aboutΒ how to style WordPress comment form. We would highly recommend that you go check that out to see how you can take your WordPress comment form to next level.
We hope that this article helps you style your WordPress comments layout. If you have any questions or suggestions, then please feel free to let us know by leaving a comment below.