Last active
August 29, 2015 14:00
-
-
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.
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
<?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