Builder CSS: Adding Additional Classes

From iThemes Codex
Jump to: navigation, search

For Categories

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


For example, if you would like to apply a specific background to all single post pages that belong to a "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.

See also

← Back to Builder Codex Home