www.n1bar.com
Member
Posted 10 months ago #
For those who want to increase their page score and speed, the following script will only load the events caledanr JS and CSS only when needed.
Paste this in your theme's functions.php
// DEREGISTER JS / CSS
function decalendarjs() {
if ( get_post_type() !== 'tribe_events' ) {
wp_deregister_script('tribe-events-pjax');
wp_deregister_script('tribe-events-calendar-script');
}
}
add_action( 'wp_print_scripts', 'decalendarjs'); // now just run the function
function decalendarcss() {
if ( get_post_type() !== 'tribe_events' ) {
wp_deregister_style('tribe-events-calendar-style');
}
}
add_action( 'wp_print_styles', 'decalendarcss'); // now just run the function
http://wordpress.org/extend/plugins/the-events-calendar/
Solid! Thanks for sharing, n1bar. This will definitely be of value to folks in your same position down the road.
tstarmer
Member
Posted 10 months ago #
I just implemented this suggestion and it only seems to workon individual event pages and on calendar pages where there is an event listed. When a calendar page is not listed the scripts and css remain deregistered. Is there another custom post type to include for those cicumstances? Or another work around.
www.n1bar.com
Member
Posted 10 months ago #
Hi, the script is supposed to de-register css and js from everywhere except when it finds a tribe_events page.
That is the purpose.
What is it that you are trying to achieve.?
tstarmer
Member
Posted 10 months ago #
I am trying to deregister the scripts and styles on all pages except the pages that use the plugin; ie indivdual events pages, the list of events page, and the pages that display the calendar of events. As I said when I use the method above it works for the individual event pages and on the events calendar page but only when an event is listed during that month. If there is a month without an event listed then the scripts and styles remain off(deregistered). I have tried it on my website as well as with a site served on my local server. It seems that if no event is listed during a particular month then the post_type does not return true for 'tribe_events'.
My question is whether there needs to be an additional condition so that calendar pages without a event will also use the scripts and styles. If so what would that additional condition be?
www.n1bar.com
Member
Posted 10 months ago #
Ah i just tested, I foresaw this, however i dont have time to find out a fix.
Click HERE and HERE
If you find a fix let us know. :)
Sorry we can't offer up more here, tstarmer. As this was a user-provided tweak we can't really provide much in terms of official support here, unfortunately, but if you need anything else let me know.