← Back to All Snippets

Dequeue Gutenberg Block Library CSS on Pages Without Blocks

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_action( 'wp_enqueue_scripts', function() {
    if ( ! has_blocks() ) {
        wp_dequeue_style( 'wp-block-library' );
        wp_dequeue_style( 'wp-block-library-theme' );
        wp_dequeue_style( 'wc-blocks-style' ); // WooCommerce block CSS
    }
}, 100 );

Eliminate render-blocking CSS on classic pages, landing pages, or lightweight custom templates by dequeuing default Gutenberg block stylesheets.

← Back to All Snippets Explore Dev Tools →