Reputation: 106
I am using a wordpress slider plugin called - Master Slider (https://wordpress.org/plugins/master-slider), which I am using on the home page of this site - http://lanarratrice-al-rawiya.com/lanarratrice
Even if the slider is used on home page, the css and js files that come with slider are being loaded on all the pages, and increasing the number of http requests. How can I make the slider css and js files to load only on the home page?
I tried using the following code snippet in functions.php file, as described in this link- (http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles) but no luck.
add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
if (!(is_front_page()) {
wp_deregister_script( 'jquery-easing' );
wp_deregister_script( 'masterslider-core' );
}
}
In the Master Slider admin section, there is an advanced setting to prevent the js and css from loading on all the pages as shown in the picture attached.
Upvotes: 0
Views: 2975
Reputation: 9782
Because you have an error in your code, you missed to close if condition with )
:
if (!(is_front_page()) {
Should be
if ( !( is_front_page() ) ) {
OR
if ( ! is_front_page() ) {
This is how you can get all the enqueued css and scripts:
global $wp_scripts, $wp_styles;
//var_dump( $wp_scripts );
//var_dump( $wp_styles );
Upvotes: 1