Support » Plugin: WP jQuery Lightbox » How to deregister script & style for pages not using lightbox?

  • joycegrace

    (@joycegrace)


    Hello,

    I’m trying to solve some site speed issues, and one of them is loading this plugin’s scripts on pages that don’t need them on my site.

    I have tried and tried to look for how to do this, but code I’ve tested is breaking the site. I think I don’t have the right naming going on.

    Can someone help me with a code snippet to make this work?

    For example, I’m not using the lightbox on my home page, so I don’t want the script and styles to load there.

    Here are references for what I’m trying to do:
    http://inspirationalpixels.com/tutorials/remove-plugin-scripts-wordpress
    https://www.fldtrace.com/load-javascript-on-specific-pages-in-wordpress
    https://css-tricks.com/taking-control-cssjs-wordpress-plugins-load/

    I’ve tried something like this, but to no avail:

    /**
     * Remove scripts + styles unless we're on the page
     * 
     */
    add_action( 'wp_enqueue_scripts', 'ac_remove_scripts' );
     
    function ac_remove_scripts() {
    	if ( is_home() ) {
    		wp_deregister_style( 'not-sure-what-goes-here' );
    		wp_deregister_script( 'wp-jquery-lightbox-swipe' );
    	}
    }
    

    I think I also need to deregister 'wp-jquery-lightbox' but not sure.

    Any help would be greatly appreciated. And sorry if I’m just being blind and not seeing what I need to see here.

    It would be great if this same code can incorporate other scripts and style from other plugins, if you can show me how to add that in the type of snippet above?

  • The topic ‘How to deregister script & style for pages not using lightbox?’ is closed to new replies.