Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.