Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter kappaluppa

    (@kappaluppa)

    I came across this code for adding event past status to body classes. However, it does not work. Any suggestion for pulling ‘past’ status into the body class? Is this the correct way to use this function?

    https://theeventscalendar.com/function/tribe_is_past/

    /*-----------------------------------------------------------------------------------*/
    /* Adds new body class
    /*-----------------------------------------------------------------------------------*/
    add_filter('body_class', 'add_browser_classes');
    function add_browser_classes($classes){
        if(tribe_is_past()) {
          $classes[] = 'events-past';
        }
    
        return $classes;
    }

    Hello,

    Oone of our devs has recommended this snippet which has worked well in the past. Try it out, and make any modifications you need to get it working just right. Please note that this is outside the scope of support we’re typically able to provide. Best of luck with your project!

    add_filter( 'body_class', 'tribe_events_past_events_body_class' );
    
    function tribe_events_past_events_body_class( $classes ) {
    
        global $wp_query;
    
        $event_date = get_query_var( 'eventDate' );
    
        if ( isset( $event_date ) ) {
    
            $this_month = current_time( 'Y-m' );
    
            if ( strtotime( $event_date ) < strtotime( $this_month ) ) {
                $classes[] = 'tribe-is-past';
            }
        }
    
        return $classes;
    }
    Thread Starter kappaluppa

    (@kappaluppa)

    Actually, this added ‘tribe-is-past to ALL events.
    I’ll see if I can make some adjustments…
    Thanks

    Brook

    (@brook-tribe)

    Howdy Kappa,

    Thanks for getting back. I can see some cases where that snippet would not work. However with some slight modification I think it should cover every case, and Hunter has already done most all of the work. Instead of checking if eventDate is in the past you could check if

    $query->get( 'eventDisplay' ) == 'past'

    I haven’t tested that, but I think it will cover every case of it displaying past events. Either way hopefully the snippet was a good starting place for your goals.

    Cheers!
    – Brook

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add past event status to body tags’ is closed to new replies.