Thesis Tip #4 – Adding Classes to Body

by Bill Erickson on November 25, 2009

Post image for Thesis Tip #4 – Adding Classes to Body

(This tutorial is specifically for the Thesis theme, but can be adapted to work with any WordPress theme).

Thesis provides certain classes on the body tag that let you narrow your CSS to specific pages:

  • custom – Styling to the whole site (overwrites Thesis default styling).
  • Page name (ex: about-us) – Styling for an individual page.
  • Category name (ex: cat_news) – Styling for a specific category page

But sometimes you need to add your own class. The two areas I usually need an extra class are for the homepage and a one for all category pages. Here’s some code you can drop into your custom_functions.php file to add both:


function custom_body_classes($classes) {
if (is_home())
$classes[] = "home";
if (is_category())
$classes[] = "category";
return $classes;
}
add_filter('thesis_body_classes','custom_body_classes');

You can use any sort of php/wordpress logic to generate your own classes this way.

All Thesis Tips:

Bill Erickson is a WordPress Consultant who builds custom websites using WordPress as a CMS and Thesis or Genesis as a framework. He’s a cofounder and resident of The Creative Space, and a cofounder of the BIL Conference (the open analog to the TED Conference).

Leave a Comment

Previous post:

Next post: