Skip to content

Instantly share code, notes, and snippets.

@nickmeagher
Created March 3, 2016 16:32
Show Gist options
  • Save nickmeagher/fa58257e4e2b264aeff3 to your computer and use it in GitHub Desktop.
Save nickmeagher/fa58257e4e2b264aeff3 to your computer and use it in GitHub Desktop.
Add taxonomy parent to the body class
/**
* Add taxonomy parent to the body class
*
* @param array $classes The current classes.
* @return array New array with updated classes
*/
function body_class_add_parent_taxonomy( $classes ) {
if ( is_tax() ) {
$taxonomy = get_queried_object();
$parent_id = isset( $taxonomy->parent ) ? $taxonomy->parent : '';
$parent_term = get_term( $parent_id, $taxonomy->taxonomy );
$classes[] = $parent_term->slug . '-taxonomy';
}
return $classes;
}
add_filter( 'body_class', 'body_class_add_parent_taxonomy' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment