Created
March 3, 2016 16:32
-
-
Save nickmeagher/fa58257e4e2b264aeff3 to your computer and use it in GitHub Desktop.
Add taxonomy parent to the body class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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