Hello, I’m trying to pass a Google Page Speed test with as many flying colours as possible.
I’m curious if anyone has some copy/paste code we can use in our functions.php file to include or exclude the IDs of pages on our site that need the event espresso javascript and css files? And its add-ons?
For example, when loading Contact Form 7 only on pages that need it, I would use this (found on lots of sites online):
/**
* Remove Contact Form 7 scripts + styles unless we're on the contact page
*
*/
add_action( 'wp_enqueue_scripts', 'ac_remove_cf7_scripts' );
function ac_remove_cf7_scripts() {
if ( !is_page('id-or-slug-goes-here') ) {
wp_deregister_style( 'contact-form-7' );
wp_deregister_script( 'contact-form-7' );
}
}
Is it possible to do this with Event Espresso?
Would that affect functionality in any way? As in, is it necessary to load these resources on every page of a site if they are not displaying events, or showing a user’s registration, etc.?
Most of Event Espresso styles and scripts are loaded only where needed. Are you looking to remove a specific CSS file or JavaScript file on some specific pages?
One other tip that will actually speed things up even more is you can use a plugin like Better WordPress Minify to compress all the scripts and styles into just a few files. This really helps because the end result will be even fewer http requests on each page load.
Viewing 1 reply thread
The support post ‘Load plugin resources only on pages that need them?’ 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.