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 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #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

#Dec 4 What is Etrieve Flow? #Dec 2 The unique operator($) in Envision Basic #Nov 25 Steps to Install Microsoft SQL Server on a MacOS #Nov 11 What is DevOps? #Nov 10 The * arithmetic operator in Envision Basic #Nov 10 What are Big Data Clusters in SQL Server?
You might also like these
Learn to create your skill bar using CSSCSSLearn to Establish Connection using MySQLi (object-oriented), MySQLi (procedural) and PDO with Example CodePHPThe simple difference between var, let and const in JavascriptJavaScriptList of WordPress directories functionsWordPressCanvas Drawing in HTML5HTMLArguments in @mixin rules in SCSS (Sass)SCSS