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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to send and receive query strings via links in Angular 9?AngularThe SQL UNION OperatorSQL/MySQLWhat Does Host-Based Intrusion Detection System (HIDS) Mean and What Are Some Advantages Over NIDS?MiscellaneousHow to overwrite file contents with new content in PHP?PHPWhat is HTMLUnknownElement?HTMLWordPress: How to find all posts from a custom post type with multiple custom fields values?WordPress