WordPress 5.0 introduced Gutenberg Blocks.
Gutenberg Blocks are great way to write contents for content creators without worrying about developing the backend pages.
There are tons of other plugins available for e.g. Advanced Custom Fields to create some kind of blocks and they are great too.
The issue
The Gutenberg Block Library adds CSS to backend and frontend both sides if it’s not blocked using some code or a plugin.
That additional CSS will create a slight slowness to your website. It’s not a huge page speed issue but it’s not ignorable issue either.
You can see this closed issue and discussion on GitHub.
The solution
We can use wp_dequeue_style function that removes a previously enqueued CSS stylesheet.
Depending on your source code, make sure you add the exact CSS file names.
function remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
}
add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css', 10 );
What about WooCommerce block CSS?
We can use the same function to remove WooCommerce block CSS too. Make sure the CSS file names are same as injected ones.
function remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'wc-block-style' );
}
add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css', 10 );
What about Storefront CSS?
Just add one more line to that function:
function remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'wc-block-style' );
wp_dequeue_style( 'storefront-gutenberg-blocks' );
}
add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css', 10 );
block functions gutenberg library style