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 . ' | ';

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

	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_script('comment-reply ');

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

You May Also Like:

67 thoughts on “WordPress: Remove Unwanted Scripts and Stylesheets

  1. Pingback: wp_dequeue_script for child theme to replace script - ExceptionsHub

  2. Pingback: Remove Wordpress WooCommerce StoreFront Header Styles - ExceptionsHub

  3. Pingback: Remove WordPress WooCommerce StoreFront Header Styles – inneka.com

  4. Pingback: wp_dequeue_script for child theme to replace script – inneka.com

  5. Pingback: what are good essay writing services

  6. Pingback: purchase a research paper

  7. Pingback: customessaywriterbyz.com

  8. Pingback: parts of a dissertation

  9. Pingback: sat essay help

  10. Pingback: what is the best college essay editing service

  11. Pingback: psychology thesis

  12. Pingback: write my college paper for me

  13. Pingback: thesis proposal format

  14. Pingback: Cephalexin

  15. Pingback: rldytwyx

  16. Pingback: what dosage of zithromax for chlamydia

  17. Pingback: mba essay writing service

  18. Pingback: writing research papers

  19. Pingback: i cant write my college essay

  20. Pingback: how a car can help me essay

  21. Pingback: business ethics essay outline

  22. Pingback: augmentin 250

  23. Pingback: can you buy lasix in mexico without a prescription

  24. Pingback: zithromax pills for sale

  25. Pingback: stromectol pill price

  26. Pingback: ventolin sale uk

  27. Pingback: price of doxycycline

  28. Pingback: prednisolone tablets 25mg

  29. Pingback: ovulation after clomid

  30. Pingback: dapoxetine paypal

  31. Pingback: diflucan sodium

  32. Pingback: synthroid substitute

  33. Pingback: buy cheap essays online

  34. Pingback: writing thesis proposal

  35. Pingback: law school essay review service

  36. Pingback: examples of dissertations

  37. Pingback: help in writing thesis

  38. Pingback: best custom essay website

  39. Pingback: custom law essay

  40. Pingback: amazon propecia

  41. Pingback: good essay writing website

  42. Pingback: college papers to buy

  43. Pingback: neurontin vs gralise

  44. Pingback: metformin indications

  45. Pingback: plaquenil hives

  46. Pingback: approved canadian pharmacies online

  47. Pingback: drugs from canada online

  48. Pingback: sildenafil 58

  49. Pingback: sildenafil price comparison uk

  50. Pingback: sildenafil 100mg usa

  51. Pingback: buy tadalafil online india

  52. Pingback: rash from amoxicillin

  53. Pingback: will amoxicillin treat strep throat

  54. Pingback: azithromycin 250 mg and alcohol

  55. Pingback: celebrex 2017 coupon

  56. Pingback: any lawsuits against celebrex

  57. Pingback: how much cephalexin for dogs

  58. Pingback: keflex antibiotic sun sensitivity

  59. Pingback: duloxetine 30 mg capsule

  60. Pingback: alcohol and cymbalta

  61. Pingback: buy tadalafil 20mg price canada

  62. Pingback: sildenafil discount generic

  63. Pingback: sildenafil cost in india

  64. Pingback: buy sildenafil us

  65. Pingback: compro sildenafilo

  66. Pingback: tadalafil generic mexico

  67. Pingback: sildenafil price 100mg

Comments are closed.