Created
March 24, 2024 00:44
-
-
Save chris-castillo-dev/a3bc7e4e3394c73e8f13cfb8754f7298 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