Add Odd / Even CSS Class Name to Posts in WordPress

You can add an ‘odd‘ and ‘even’/ CSS class name to sequential posts in a blog /archive page by utilising the post_class filter.

You can add the snippet below in your theme functions.php file.

To target specific posts in an archive or home page, you can either wrap the code in a conditional statement or write your CSS with a specific Class hierarchy to target the post in the right place.

Leave all Comment