Builder CSS: Adding Additional Classes

From IThemes Codex
Revision as of 10:22, July 30, 2013 by Kristen (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In Builder (and in many other themes) by default the body class of a single post page does not contain the categories under which the post has been categorized.


If you would like to apply a specific background to all single post pages that belong to say, "Recipes" category then by using the following code "recipes" will be one of the classes that gets applied to body class. Therefore we can target any element on a single post page belonging to "Recipes" category by prepending the CSS selector with "".

Add the following before closing PHP tag in child theme's functions.php:

// add category nicenames in body class
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes[] = $category->category_nicename;
return $classes;

add_filter('body_class', 'category_id_class');


Note: In Builder, category/categories are present for post class by default.

Personal tools
iThemes Codex
Codex Navigation