Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chris-castillo-dev/a3bc7e4e3394c73e8f13cfb8754f7298 to your computer and use it in GitHub Desktop.
Save chris-castillo-dev/a3bc7e4e3394c73e8f13cfb8754f7298 to your computer and use it in GitHub Desktop.
/**
* Add Page Terms (Taxonomy) to Body Tag
*/
function pro_page_taxonomy_class_to_body( $classes ){
if ( $pageTaxonomy = get_the_terms( get_the_ID(), 'my_taxonomy_slug' ) ) {
foreach( $taxonomyTerm as $term ){
if(is_array($term)){
if(!empty($term['slug'])){
$termClass = 'mytaxonomy-' . $term['slug'];
array_push( $classes, $termClass );
}
}else{
$termClass = 'mytaxonomy-' . $term->slug;
array_push( $classes, $termClass );
}
}
}
return $classes;
}
add_filter( 'body_class', 'pro_page_taxonomy_class_to_body' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment