Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active July 27, 2016 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/6ba85a263e9f9d67d70b1febbe0e6aa9 to your computer and use it in GitHub Desktop.
Save Pebblo/6ba85a263e9f9d67d70b1febbe0e6aa9 to your computer and use it in GitHub Desktop.
An example of how to add the EE terms to the body_class
<?php //Please do not add the opening PHP tag if you already have one
function tw_ee_taxonomy_in_body_class( $classes ){
//Check if within a single EE event post.
if( is_singular( 'espresso_events' ) ) {
//Pull the terms used for the Event.
$custom_terms = get_the_terms( 0, 'espresso_event_categories' );
//If we have custom terms, add them to the body class
if ( $custom_terms ) {
foreach ( $custom_terms as $custom_term ) {
//Add each term slug to the body class with the prefix 'category-'
$classes[] = 'category-' . $custom_term->slug;
}
}
}
//Return the body classes
return $classes;
}
add_filter( 'body_class', 'tw_ee_taxonomy_in_body_class' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment