(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:- Adding “nofollow” to Category Links
- Thesis Tip #18 – Full Width Navigation
- Thesis Tip #17 – Adding Content Between Posts
- Thesis Tip #16 – Redirect Pages
- Thesis Tip #15 – Custom Author Pages
- Thesis Tip #14 – Add Related Posts Before Comments Link
- Thesis Tip #13 – Using Gravatars in WordPress
- Thesis Tip #12 – Adding Custom Headers to Category Pages
- Thesis Tip #11 – Clickable Logo in Header
- Thesis Tip #10 – Filter Categories from Homepage
- Thesis Tip #9 – Custom Options Page
- Thesis Tip #8 – Change Next and Previous Post Text
- Thesis Tip #7 – Import and Export Your Design
- Thesis Tip #6 – Print Stylesheets
- Thesis Tip #5 – Featured Content Rotator
- Thesis Tip #4 – Adding Classes to Body
- Thesis Tip #3 – Multiple content areas
- Thesis Tip #2 – Additional Sidebars
- Thesis Tip #1 – Custom Images and Category Pages
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).
