Yogesh Chauhan's Blog

How to remove the Gutenberg Block Library CSS from WordPress?

in WordPress on July 25, 2021

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 );


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
What is HTMLUnknownElement?HTMLCreate a menu with a curtain falling animation using CSS and JavaScriptCSSHow to show slider value in HTML5 range input using JavaScript?HTML@mixin and @include in SCSS (Sass)SCSSHow to create bouncing balls using HTML canvas and JavaScript?HTMLWhat is an API?Miscellaneous