Created
March 22, 2024 00:27
-
-
Save PropelDMS/b704bd7dbf0163bd281d3b398074c0e7 to your computer and use it in GitHub Desktop.
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 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