Support

Home Forums Event Espresso Premium My template file is stripped from the body class on single events

My template file is stripped from the body class on single events

Posted: June 19, 2015 at 10:40 am


Cathy Silverman

June 19, 2015 at 10:40 am

I have a site that has two distinct looks depending on what section you are in. I enqueue different CSS styles based on the template name. EE4 is stripping my template name out of the body class defaulting to the base CSS file. Is there a workaround for this? I have events that need to take on both styles depending on what section you are loading the event from.


Josh

  • Support Staff

June 19, 2015 at 12:04 pm

Hi Cathy,

Do you have some logic in place to switch the template for the event depending on which section you are loading the event from? If so, can you post the code into a pastebin or a gist so we can take a look?


Cathy Silverman

June 19, 2015 at 1:08 pm

The only logic I am using is a function to enqueue the right css based on what template is chosen when you create the page. when creating the event, I can choose the template, it uses the template visually but the template name is no longer in the body class, so the css isn’t enqueued.

my enqueue script.
http://pastebin.com/zPCPL2UA

This is Bryan, under Cathy’s account


Cathy Silverman

June 19, 2015 at 1:14 pm

Josh, I forgot this.

A basic page calling the right template in the body class:
class=”page page-id-729 page-child parent-pageid-220 page-template page-template-template-CFW-rt-sidebar-no-title page-template-template-CFW-rt-sidebar-no-title-php logged-in admin-bar no-customize-support CFW give-test-mode give-page group-blog”

The event single page.
class=”single single-espresso_events postid-1746 logged-in admin-bar no-customize-support CFW give-test-mode give-page group-blog”


Josh

  • Support Staff

June 19, 2015 at 3:00 pm

Hi Bryan,

It turns out that the is_page_template() function only returns true if it’s a WordPress page post type. Event Espresso events are espresso_events, not pages. Here’s a link that shows what happens in WP Core when is_page_template() runs:

https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/post-template.php#L1663

A possible solution is mimic the core WP function, except check for an espresso_events post type instead of a page post type. Here’s some example code:

https://gist.github.com/joshfeck/599a3d09032a6164c873

The support post ‘My template file is stripped from the body class on single events’ 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.

Event Espresso