Support

Home Forums Event Espresso Premium Help with custom plugin templates / hooks / filters

Help with custom plugin templates / hooks / filters

Posted: July 25, 2018 at 3:30 pm

Viewing 19 reply threads


Praxis

July 25, 2018 at 3:30 pm

Hello!

I am attempting to make some pretty serious customizations to both the default events page as well as the events grid template plugin (seen here).

Obviously I don’t want to touch the core stylesheets and template files, since they’ll be wiped whenever an upgrade comes along. All I’m trying to do is shuffle around and expand on the structure within my child theme, and in the case of the events page, output some custom field boxes on the sidebar.

What would be the easiest and most brain-dead simple way to go about this? Hooks and filters? I have an elementary grasp on them, but anything to get me going in the right direction would be greatly appreciated. I just want my template modifications to be separated from the core files so they survive updates.

Thank you very much!


Josh

  • Support Staff

July 25, 2018 at 9:57 pm

Hi Hilary,

Welcome aboard!

For the default event list page, you’ll follow these steps:
1) Make a copy of the parent theme’s archive.php template
2) rename the copy archive-espresso_events.php
3) put the copy into the child theme
4) optional, but recommended if your custom list will include the extra event content, add the following code to your child theme’s functions.php file:
add_filter( 'FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', '__return_true' );
5) Edit the copy that’s in the child theme
Source:
https://eventespresso.com/wiki/ee4-custom-post-types/#archive_event_template

Then, for the grid template plugin, you’ll follow these steps:
1) Make a copy of the grid template plugin’s espresso-grid-template.template.php file (located in the /templates folder)
2) Put the copy into your child theme
3) Edit the copy that’s in the child theme

Finally, if you have CSS customizations, those go in the style.css stylesheet of the child theme. If you’re having trouble overriding some default styles, you do well to use slightly more specific CSS selectors. This guide is not only fun, but very accurate:

https://stuffandnonsense.co.uk/archives/css_specificity_wars.html

(in most cases you will not need to go to0 far into the dark side)


Praxis

July 26, 2018 at 12:27 pm

Josh,

Thanks a lot, that worked perfectly.

As far as editing core Event Espresso files goes, where would I find those? Specifically I’m looking to edit the structure of how individual event pages are laid out. I assume it’s as simple as what you had me do here (moving files to my children theme folder), but I’m not sure what the exact template file is called or where to find it.

Thanks again~


Josh

  • Support Staff

July 26, 2018 at 12:33 pm

It may not be as simple because the event page content is added via filter functions on the WordPress the_content filter hook. So it will depend on what you’re editing.

So if you’re looking to edit the outer structure of the single event page, you’ll follow this:
https://eventespresso.com/wiki/ee4-custom-post-types/#single_event_template

If you’re editing the structure of the individual parts of event content, the you can copy templates from the /public folder from within the plugin and put the copy into your child theme. For example to edit the section that has the venue information, you’ll copy over the content-espresso_events-venues.php template from the /public/Espresso_Arabica_2014 folder, then edit the copy in your child theme.


Praxis

July 26, 2018 at 2:17 pm

Ah, yeah! I’m just trying to change the structure of the single event page. I understand the process enough after reading that link. Is Event Espresso completely contained to the plugins folder, or are there files elsewhere? I see a lot of the plugins / extensions in there, but not the core files themselves. For instance, where would I find single-espresso_events.php?


Josh

  • Support Staff

July 26, 2018 at 2:46 pm

All of Event Espresso’s core files are within its folder within /wp-content/plugins/. You will find a single-espresso_events.php template file in the public folder(within the theme folder there), but you shouldn’t use that file.

Instead, you’ll need to base your single-espresso_events.php template off of your theme’s single.php template. WordPress just uses the single.php template file from your theme when it outputs an event page. If you want to add a single-espresso_events.php file to your theme, WordPress will use that file instead of single.php. This guide explains more:

https://developer.wordpress.org/themes/basics/template-hierarchy/


Praxis

July 26, 2018 at 4:48 pm

OK great, that makes perfect sense. And similarly would the sidebar on a single events page be modified through sidebar.php?


Josh

  • Support Staff

July 27, 2018 at 6:48 am

Possibly. If you have this code in your single events template:

<?php get_sidebar(); ?>

Then yes, you could edit the sidebar.php template and your edits will affect the sidebar for the events page and every other page where the template calls get_sidebar().

Quite likely you want a specialized sidebar just for events, so what you could do is put this code in your single events template:

<?php get_sidebar('for-events'); ?>

Then name your specialized sidebar template file
sidebar-for-events.php.

Source:
https://developer.wordpress.org/reference/functions/get_sidebar/


Praxis

August 2, 2018 at 12:43 pm

Josh,

OK so, after going through the code and messing around with sidebar.php, I’m realizing that the info I want to shift into the sidebar is actually in single.php. So for instance if I wanted to move pricing details, calendar, any custom fields to the right of my event info . . . how would I go about doing that? I could very easily use my theme’s built-in scaleable columns, but how do I separate Event Espresso sidebar items from the rest of the content?

Thanks!


Josh

  • Support Staff

August 2, 2018 at 1:02 pm

You could alter the markup within a variation of single.php, in this case single-espresso_events.php, then move the elements into a division that makes up a separate column. I mentioned earlier that you can copy templates from the /public folder from within the plugin and put the copy into your child theme.


Praxis

August 2, 2018 at 1:21 pm

So I got into the EE plugins template folders and grab the info I need, then drop them in my new single-espresso_events.php with style tags around them? Or would it be simpler to, as you say, copy over those templates into my child theme and apply my new styles there . . . without combining the two files?


Josh

  • Support Staff

August 2, 2018 at 1:22 pm

You could do either.


Praxis

August 2, 2018 at 1:39 pm

And, just to be clear, the templates added to the new single.php file would override the default plugin styles?


Josh

  • Support Staff

August 2, 2018 at 1:42 pm

No, the default plugin styles would still remain unless you’ve added additional styles that override the default plugin styles.


Praxis

August 2, 2018 at 2:32 pm

Ahhh OK. I’ll target the plugin template styles in my child theme stylesheet to move them into a sidebar on the right. I imagine that’s the trick.


Josh

  • Support Staff

August 2, 2018 at 2:38 pm

The plugin template styles do not attempt to control the layout though, so that’s probably not necessary.

If your theme already has markup & styles for a primary content area (or wider left column) and a secondary content area (for a sidebar to the right), you can add your markup to the template and the theme styles will take care of the rest.


Praxis

August 3, 2018 at 4:14 pm

Hmm. I’m still having a few issues. Because EE’s info is just part of the WordPress loop, I can’t distinguish where it’s coming from among the many plugin folders I have.

See here:

This EE info just ends up displayed in the loop along with the rest of the content. I’m not exactly sure where to go to separate it. This is how many plugin folders I’m scanning through:

Thanks for your help!


Josh

  • Support Staff

August 3, 2018 at 5:01 pm

Hi,

The event info is not actually coming from any of those plugin folders. The information getting injected into the loop via the WordPress the_content filter. The template parts that get injected are all in the EE4 core plugin’s public folder.

So the way forward for you will be to remove what’s injected into the content via the_content filter. So change this in your theme’s functions.php file:

add_filter( 'FHEE__EED_Event_Single__template_include__allow_custom_selected_template', '__return_true' );

to this:

add_filter( 'FHEE__EED_Event_Single__template_include__allow_custom_selected_template', '__return_false' );

Then, you can pull in the various template parts in your custom single-espresso_events.php template. A very simple example follows:

<?php espresso_get_template_part('content', 'espresso_events-datetimes'); ?>
<?php espresso_get_template_part('content', 'espresso_events-tickets'); ?>


Praxis

August 6, 2018 at 3:29 pm

Yeah! That’s it. Thank you.

Is there a list somewhere of all the EE template parts to call from?


Josh

  • Support Staff

August 6, 2018 at 3:45 pm

content-espresso_events-header.php
content-espresso_events-datetimes.php
content-espresso_events-tickets.php
content-espresso_events-venues.php
content-espresso_events-thumbnail.php

Viewing 19 reply threads

The support post ‘Help with custom plugin templates / hooks / filters’ 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