Hello,
While optimizing the theme for speed, I noticed genesis slider loads in every page even though we only use it for the homepage.
To make the user experience more enjoyable (and get a better Google Pagespeed ranking), I thought it might be good dequeue’ing the js and stylesheet of the slidershow to only load in the homepage.
This is the code I have so far, but it doesn’t seem to be working;
// Dequeue css and js for Genesis Slider
function my_dequeue_styles() {
wp_dequeue_style( 'slider_styles' );
}
function my_dequeue_javascript() {
wp_dequeue_script( 'flexslider' );
}
// Conditionally load css and js for Genesis Slider
function my_enqueue_style() {
if( is_front_page() ) {
wp_enqueue_style( 'slider_styles', false );
}
}
function my_enqueue_script() {
if( is_front_page() ) {
wp_enqueue_script( 'flexslider', true );
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_style' );
add_action( 'wp_enqueue_scripts', 'my_enqueue_script' );
Can you spot anything that I might have missed?
Cheers