Skip to content

Instantly share code, notes, and snippets.

@bejes
Forked from davemac/gist:1480832
Created December 15, 2011 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bejes/1480933 to your computer and use it in GitHub Desktop.
Save bejes/1480933 to your computer and use it in GitHub Desktop.
WordPress get the category parent slug and include in body_class
<?php
if (is_single() || is_category()) {
$category = get_the_category();
$nice_name=array();
foreach($category as $c)
{
$parent = $c->category_parent;
$parent_cat =get_category($parent);
$nice_name[]= $parent_cat->category_nicename;
}
}
?>
<body <?php body_class($nice_name); ?>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment