Support

Home Forums Event Espresso Premium Add body class to single past event

Add body class to single past event

Posted: June 5, 2018 at 1:20 pm


Jon Valade

June 5, 2018 at 1:20 pm

Hello,

We are currently adding a button to single events with the following function:

add_action('AHEE_event_details_after_post', 'cta');
function cta() {
if(is_singular( 'espresso_events' )) {
	$se_title=single_post_title('', FALSE);
	$cta="<div class='cta'><a href='#ticketbox'><div class='cta_liner'>Buy tickets to <span class='event_cta'> " . $se_title . "</span> now!</div></a></div>";
} 
echo $cta;
}

I would like to hide this button on past events. Is there a way to add a body class of “expired” or similar on single past events so I can hide it with CSS?

Many thanks.


Josh

  • Support Staff

June 5, 2018 at 1:46 pm

You could actually just not add the button at all on expired events by making a small modification to your code:

add_action('AHEE_event_details_after_post', 'cta');
function cta( $post ) {

if(is_singular( 'espresso_events' )) {
    if($post->EE_Event instanceof EE_Event) {
        if($post->EE_Event->get_active_status() != 'DTU') {
            return;
        }
    }
    $se_title=single_post_title('', FALSE);
    $cta="<div class='cta'><a href='#ticketbox'><div class='cta_liner'>Buy tickets to <span class='event_cta'> " . $se_title . "</span> now!</div></a></div>";
} 
echo $cta;
}


Jon Valade

June 5, 2018 at 1:48 pm

Brilliant, thanks – works perfectly.

The support post ‘Add body class to single past event’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Jon Valade 4 months, 1 week ago ago

Topic Tags

Notifications

This topic is:
pending
Do NOT follow this link or you will be banned from the site!