Arya Dhiratara

Remove Unwanted Plugins’ CSS and JS

How To

The powerful wp_dequeue_script and wp_dequeue_style functions. These were actually the first php function that I learn when I built my first website. Turns out, I’ve been a freak for website speed and performance since the beginning.

Basically, both functions has the same purpose: to remove unwanted CSS and JavaScripts loaded by our theme, plugins, or even from the WordPress core itself. wp_dequeue_script is for JavaScript files, and wp_dequeue_style is for CSS files.

The standard function will look like this:

function tw_unload_files() {
 
	wp_dequeue_style ( 'wp-block-library' );
	wp_dequeue_style ( 'wc-block-style' );
 
}
add_action( 'wp_enqueue_scripts', 'tw_unload_files', PHP_INT_MAX );

The code above will remove your Gutenberg’s blocks and WooCommerce blocks’s CSS.

I don’t know why the WP Core Team not load them conditionally, the Gutenberg blocks’s CSS is loaded automatically by default, site-wide, even tough we are not using it. It’s the same with the WooCommerce block’s CSS if we install WooCommerce plugin.

Leave a Comment