add venue body class

Home Forums Calendar Products Events Calendar PRO add venue body class

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1515938
    Benedikt
    Participant

    Hey there!
    I want to add the venue nicename to my body class and change the background depending on the venue the event is listed for. The event overview body however needs to be untouched.
    My Problem: The venue classes are all added up to the body whenever the overview “events” is opened. So all bodys are being loaded. I found a solution, but im not sure if its really stable – Im not in to php to be honest.

    ‘add_filter(‘body_class’,’conf_class’);
    function conf_class($classes) {

    $post_id = get_the_ID();
    $venue = tribe_get_venue($post_id);

    if (is_tax()){
    $venue = ‘myVenue-‘ . $venue;
    $classes[] = $venue;
    return $classes;
    } else {return $classes;}
    }’

    My questions on this peace of code:

    – I added “is_tax()” because it ocures to me, that “events” page has no custom taxonomies – can I ask for specific taxonomies like string “category nicename” here? Would be better I guess. something like “if is_tax(“category name”).

    – In the end I had to return the untouched classes. If I dont return them, some classes go missing (like for closed tribe filter bar). Is that correct?

    #1516041
    Benedikt
    Participant

    Update: oaky, my code does not really make sense.

    What I need to do:

    I need to ask for the venue name before I can add the body class.
    -> if is venue x? add body class x
    -> if is venue y? add y
    -> if is both add nothing
    -> is “events” add nothing.

    How can I do that?

    Something like this?

    add_filter('body_class','conf_class');
    function conf_class($classes) {
    
        $post_id = get_the_ID(); 
    	$v1 = 'Docks';
    	$v2 = 'Prinzenbar-Hamburg';
        $venue = tribe_get_venue($post_id); 
    	
    	if ($venue == $v1 ^ $v2){
    	$venue = 'myVenue-' . $venue;
      $classes[] = $venue;
    	  return $classes;
    	}else {return $classes;}
    }
    • This reply was modified 8 years ago by Benedikt.
    #1517055
    Victor
    Member

    Hi Benedikt! This is a duplicate of https://theeventscalendar.com/support/forums/topic/add-venue-based-class-to-body/ so I’ll go ahead and close it.

    Please refer to that thread so I can help you further 🙂

    Thanks,
    Victor

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘add venue body class’ is closed to new replies.