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.
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?
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.
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”
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:
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:
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.
Support forum for Event Espresso 3 and Event Espresso 4.