How to Add the Parent Category as a Class in body_class()

<?php $class=''; /* Make it void by default */

if ( is_single() || is_category() ) { /* Only do this if we're on a single post or category page */
$category = get_the_category();
$parent = $category[0]->category_parent;
$class = get_cat_name($parent); /* assign the permalink name for the parent category to the object $class */

<body <?php body_class($class); /* This will add our custom class, which is void if we aren't on a single post or category page */ ?>>


Popular posts from this blog

Set limit wp_nav_menu

Conut document have children that are show in navigation