Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active August 29, 2015 14:00
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 joshfeck/11383932 to your computer and use it in GitHub Desktop.
Save joshfeck/11383932 to your computer and use it in GitHub Desktop.
Adds a class name to the Event Espresso event post's post class so events that belong to a specific category can be uniquely styled with CSS. Requires Event Espresso 4.2.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
// Add a class name to the event post's post class that's based on the category it's assigned to
add_filter( 'post_class', 'ee_add_taxonomy_post_class', 10, 3 );
function ee_add_taxonomy_post_class( $classes, $class, $ID ) {
$taxonomy = 'espresso_event_categories';
$terms = get_the_terms( (int) $ID, $taxonomy );
if( !empty( $terms ) ) {
foreach( (array) $terms as $order => $term ) {
if( !in_array( $term->slug, $classes ) ) {
$classes[] = $term->slug;
}
}
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment