How to prevent loading of all plugin’s resources?

You could try echoing wp_head and wp_footer to see what they contain but unfortunately that’ll miss stuff some of the authors hardcode. Basically what I do is wp_dequeue/wp_deregister based on what I see being loaded in either the source, error-logs or even just looking within each of the installed plugins to see whats being called. I find it easier to download production sites to my local dev environment. Using Notepad++ I then click Search -> Find in all files -> Specify the plugins dir (or themes) on my local development environment and search for patterns like wp_enqueue even *.js and so on since I get a better picture and what can be loaded. I then make the needed changes on the live environment.

If you identify scripts you do not want, Pop them into a function that looks something like this inside your themes function.php file:

function wp_getridofscript() {
   wp_dequeue_script( 'jquery-ui-core' );
   wp_deregister_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_getridofscript', 100 );

You can have as many as you want and don’t need to bother writing a separate function for each. IE:

function wp_getridofscript() {
   wp_dequeue_script( 'jquery' );
   wp_deregister_script( 'jquery' );
   wp_dequeue_script( 'jquery-ui-core' );
   wp_deregister_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_getridofscript', 100 );

Leave a Comment