Remove Gutenberg CSS on the front end
For sites built with Elementor or the classic editor.
Don’t use this if you use blocks or a block theme.
add_action( 'wp_enqueue_scripts', function() {
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'global-styles' );
wp_dequeue_style( 'classic-theme-styles' );
}, 100 );
Licensed under GPL-2.0-or-later, provided as is. Review and test it before using it on a live site.
How it works
WordPress loads the block editor’s styles on every page, even when the content isn’t built with blocks. The snippet runs late on wp_enqueue_scripts and removes four of them:
wp-block-library: the styles for every core block.wp-block-library-theme: extra block styles some themes turn on.global-styles: the inline CSS generated from theme.json.classic-theme-styles: button and file block styles for classic themes.
When not to use it
Skip it if your pages use blocks, if you run a block theme, or if you use the WooCommerce Cart and Checkout blocks. Without these styles, block layouts, columns and buttons lose their styling.
How to check it works
View the source and search for wp-block-library-css. It should be gone. Then go through your main pages and check nothing looks different.
How to undo it
Remove the code and clear any page cache.
How to add this snippet
- Copy the code above.
- Paste it at the end of your child theme’s
functions.php, in Appearance → Theme File Editor or over FTP. - Save, then open the site and check that everything works. If something breaks, remove the code.
Need more than one? Open this snippet in the builder, turn on the others you want and copy them as one functions.php, or download them as a small plugin.
More in Performance
- Disable the emoji scriptsOne less script on every page. Browsers render emoji natively anyway.
init - Limit post revisionsKeeps the database from filling up with hundreds of old revisions.
wp_revisions_to_keep - Control the Heartbeat APIStops Heartbeat on the front end and slows it down in wp-admin. The post editor keeps it, so autosave and post locking still work.
heartbeat_settings