Mastering the post_class() Function
November 20, 2014 § Leave a comment
post_class() function is one of the many functions provided by WordPress to facilitate theme development. As the name suggests, the
post_class() function outputs an HTML class attribute and sets its value to classes related to the post being output.
The correct way to use the function is to add it to the HTML tag that serves as the container for the post content:
The post classes
The number and the name of the classes output by the
post_class() function depends on the properties attached to a specific post. Here is an overview of the different possibilities and the contexts in which they are added.
WordPress respects the hAtom microformat. Therefore every post has an
.hentry class added to it to respect the specification. This class is a great way to target both posts and pages in your CSS.
An example of the post ID class might be
View original post 1,294 more words