Skip to content

Instantly share code, notes, and snippets.

@seanchayes
Last active April 20, 2016 01:03
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 seanchayes/5c6cc0b4b9d75104a70cc7c9c1f374b5 to your computer and use it in GitHub Desktop.
Save seanchayes/5c6cc0b4b9d75104a70cc7c9c1f374b5 to your computer and use it in GitHub Desktop.
Add body class "past-event" to single event view for The Events Calendar by Modern Tribe
add_filter( 'body_class', 'tribe_events_past_events_body_class' );
function tribe_events_past_events_body_class( $classes ) {
// Check if the Events Calendar main class exists and if not just return the classes
if ( ! class_exists( 'Tribe__Main' ) ) {
return $classes;
}
// Check if we are viewing a single event
if ( is_singular( 'tribe_events' ) ) {
// Retrieve the event details and calculate if it has passed or not
$event = get_queried_object();
// This code copied from Single_Event.php where an event has passed check is made
$gmt_offset = ( get_option( 'gmt_offset' ) >= '0' ) ? ' +' . get_option( 'gmt_offset' ) : ' ' . get_option( 'gmt_offset' );
$gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset );
if ( ! tribe_is_showing_all() && strtotime( tribe_get_end_date( $event->ID, false, 'Y-m-d G:i' ) . $gmt_offset ) <= time() ) {
$classes[] = 'tribe-is-past';
}
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment