Skip to content

Instantly share code, notes, and snippets.

@felipefernandes
Last active August 29, 2015 13:58
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 felipefernandes/9961202 to your computer and use it in GitHub Desktop.
Save felipefernandes/9961202 to your computer and use it in GitHub Desktop.
Wordpress: Adding parent class in Body Class section
<?php
/**
* Adds parent category class in BodyClass()
* @author felipefernandes (eu@felipfernandes.nu)
*/
function add_parent_cat_in_body_class( $classes ){
$category = get_queried_object();
$parent_id = $category->category_parent;
$parent = get_category( $parent_id );
if ( ! empty( $parent ) ) {
$classes[] = 'category-'.$parent->slug;
}
return $classes;
}
add_filter('body_class','add_parent_cat_in_body_class', 10);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment