WordPress: Remove Unwanted Scripts and Stylesheets

| Ngoc Nguyen

I use NextGen gallery to organize my images and photos, but I don’t use it to display the galleries on my site. In order to optimize site speed, I wanted to prevent Nextgen scripts and stylesheets from loading.

Getting the Scripts and Stylesheets Handle

Before, we can remove the scripts and stylesheets from loading, we need to know their handle names. The easiest way to do this is to edit the functions.php file. Afterwards we simply navigate to any page and the handle names will be printed out at the top.


function wpcustom_inspect_scripts_and_styles() {
	global $wp_scripts;
	global $wp_styles;

	// Runs through the queue scripts
	foreach( $wp_scripts->queue as $handle ) :
		$scripts_list .= $handle . ' | ';
	endforeach;

	// Runs through the queue styles
	foreach( $wp_styles->queue as $handle ) :
		$styles_list .= $handle . ' | ';
	endforeach;

	printf('Scripts: %1$s 
Styles: %2$s', $scripts_list, $styles_list); } add_action( 'wp_print_scripts', 'wpcustom_inspect_scripts_and_styles' );

Removing the Unwanted Scripts and Stylesheets

Now that we have the handle names, we can call wp_deregister_style() to remove the unwanted scripts and stylesheets. In the sample below, I am removing the Nextgen scripts and lightbox stylesheets from firing throughout the site. If you need to remove them only for specific pages or sections, you can use WordPress’ conditional tags.


function wpcustom_deregister_scripts_and_styles(){
	wp_deregister_style('foobox-1-4-min');
	wp_deregister_style('foobox-mini-invert');
	wp_deregister_style('foobox-blue');
	
	wp_deregister_script('photocrati_ajax');
	wp_deregister_script('lazy_resources');
	wp_deregister_script('comment-reply ');
}

add_action( 'wp_print_styles', 'wpcustom_deregister_scripts_and_styles', 100 );

You May Also Like:

32 thoughts on “WordPress: Remove Unwanted Scripts and Stylesheets

  1. Pingback: sinusitis augmentin

  2. Pingback: keflex synonym

  3. Pingback: ciprofloxacin 250

  4. Pingback: azithromycin pneumonia

  5. Pingback: omnicef pill

  6. Pingback: ndc augmentin

  7. Pingback: zithromax generation

  8. Pingback: erythromycin biaxin

  9. Pingback: omnicef fda

  10. Pingback: clarithromycin

  11. Pingback: celebrex generic equivalent

  12. Pingback: How to Remove Styles, Scripts, and More from your WordPress Parent Theme – Geniuswp

  13. Pingback: canada pharmacies

  14. Pingback: canadian drugstore

  15. Pingback: https://kewertyn.wordpress.com/2022/04/27/expect-more-virtual-house-calls-out-of-your-doctor-thanks-to-telehealth-revolution/

  16. Pingback: https://kertubs.mystrikingly.com/

  17. Pingback: 6270e49a4db60.site123.meblogthe-untold-secret-to-mastering-aspirin-in-just-7-days-1

  18. Pingback: canadian pharmaceuticals online

  19. Pingback: canadadrugs

  20. Pingback: no 1 canadian pharcharmy online

  21. Pingback: canadian online pharmacies

  22. Pingback: canada pharmacies online

  23. Pingback: site592154748.fo.team

  24. Pingback: dkyubn.bizwebs.com

  25. Pingback: https://kewburet.wordpress.com/2022/04/27/how-to-keep-your-workers-healthy-during-covid-19-health-regulations/

  26. Pingback: https://628f789e5ce03.site123.me/blog/what-everybody-else-does-when-it-comes-to-canadian-pharmacies

  27. Pingback: https://canadian-pharmaceutical.webflow.io/

  28. Pingback: canadian discount pharmacies

  29. Pingback: https://kedmnx.estranky.sk/clanky/online-medicine-tablets-shopping-the-best-manner.html

  30. Pingback: canadian pharmacies mail order

  31. Pingback: javascript – wp_dequeue_script for child theme to replace script – Tech Notes Help

  32. Pingback: canadadrugs

Comments are closed.