Adding Event category to body class

WordPress Event Management, Calendars & Registration Forums General Question Adding Event category to body class

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 6 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #27689

    Is it possible to automatically add the event categories to the body class, so I can use them with css.

    Paksha Thullner
    #27693

    Yes, try adding this to your theme’s functions.php:

    add_filter( 'body_class', function( $classes ) {
         if ( is_singular( 'event' ) ) {
             $cats = get_the_terms( get_the_ID(), 'event-category' );
             if ( $cats && ! is_wp_error( $cats ) ) {   
                 foreach ( $cats as $cat ) { 
                     $classes[] = sanitize_html_class( 'eo-event-cat-' . $cat->slug );
                 }
             }
         }
         return $classes;
    } );
    
    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.