Skip to content

Instantly share code, notes, and snippets.

@davemac
Created December 15, 2011 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davemac/1480832 to your computer and use it in GitHub Desktop.
Save davemac/1480832 to your computer and use it in GitHub Desktop.
WordPress get the category parent slug and include in body_class - works in posts with multiple cats
<?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;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment