I am customizing some of the Hivepress email templates via the hivepress/v1/emails/{email_name} hook. I have also used hooks to filter the Add listing form and others.
I use WP Code to insert those snippets because I do not use child themes, but I would like some guidance as to where/when these snippets should run. I have these options:
Run Everywhere
Frontend Only
Frontend Conditional Logic (running the snippet later with conditional logic rules in the frontend)
On Demand (Execute this snippet on demand or programmatically just when you need it)
Site Wide (Frontend)
Site Wide Header
Site Wide Body
Site Wide Footer
Page specific
Via shortcode insertion
I want to avoid running the snippets on every page a user visits, to reduce load, but I don’t know exactly when/where some actions occur, like email sending.
In the email filter hooks case, would it be possible to run the snippet as a shortcode inside the respective email template? I know shortcodes do work inside templates…
I think you did not fully understand my previous message.
I am using a plugin, WP Code, to insert my code snippets. My question is:
Where/when do I run these snippets for better efficiency?
The WP Code plugin gives me all those options I mentioned above (frontend, site wide header, etc…) to let the snippet run.
In the case of snippets containing filter hooks for, for example, email templates, I don’t know when emails will be sent, so I don’t know where to place the snippet.
I want to avoid running the snippets on every page for every user.
I tried inserting a shortcode in a HP email template containing a snippet with an email filter hook, and indeed it filters the email when triggered. Will this be the best option, also for listing/booking filter hooks?
Thanks for the details. You can select “Run everywhere,” and this will not affect your website speed, etc. In other words, you do not have to divide snippets by scopes. This is because a hook is an event in itself, and the code is executed until the event occurs (i.e., the code will not be executed on every page, but only on a specific action).