Performance PHP Intermediate

Remove Block Library CSS on Non-Block Posts

Last updated: May 6, 2026

WordPress loads its block library stylesheet, wp-block-library, on every page of your site, regardless of whether any blocks are actually used in the content being displayed. For posts written in the classic editor, pages built with a page builder like Bricks or Elementor, or any content that uses no Gutenberg blocks, this stylesheet is dead weight. It adds an HTTP request and around 10–18KB of CSS that applies to elements that don’t exist on the page.

The Code

Add this to your functions.php or a site-specific plugin. It runs at priority 100 to ensure it fires after all other enqueueing is complete, then checks whether the current post contains block markup before removing the stylesheets.

The has_blocks() Check

has_blocks() examines the post content string for the presence of Gutenberg block comment delimiters, the <!-- wp:block-name --> syntax that WordPress uses to store block data. If any block markup is found, the function exits early and the stylesheets remain. If no blocks are found, it’s safe to remove the block library styles entirely.

Passing $post->post_content explicitly rather than relying on the global post context ensures the check runs against the correct post even in cases where the global post state might be unreliable.

What Gets Removed

wp-block-library is the core block CSS containing styles for all built-in blocks. wp-block-library-theme is a companion stylesheet with theme-specific block style variations. wc-block-style is WooCommerce’s block stylesheet, safe to remove on non-WooCommerce pages without block-based cart or checkout. global-styles is the CSS generated from theme.json variables; removing it is appropriate for pages where those variables have no effect, though be cautious if your classic content relies on theme.json-defined custom properties for typography or colours.

Page Builder Sites

On sites where all pages are built with a page builder and no posts use the block editor, this snippet removes the block library stylesheet universally from all singular templates. It’s one of the highest-impact debloat actions available for Bricks Builder, Elementor, and similar setups because those builders have their own CSS systems and the WordPress block library stylesheet is entirely redundant.

Template and Archive Pages

The snippet only runs on singular posts and pages. Archive pages, the homepage, search results, and other non-singular templates are excluded because the block content check requires a specific post. If you use block-based widgets or a block-based sidebar on archives, those templates need the block library styles and should remain excluded from the removal.

functions.php
add_action( 'wp_enqueue_scripts', function() {
    if ( ! is_singular() ) return;

    global $post;
    if ( ! $post ) return;

    // Check if the post content contains any block markup
    if ( has_blocks( $post->post_content ) ) return;

    // No blocks found, safe to remove the block library stylesheet
    wp_dequeue_style( 'wp-block-library' );
    wp_dequeue_style( 'wp-block-library-theme' );
    wp_dequeue_style( 'wc-block-style' ); // WooCommerce block styles
    wp_dequeue_style( 'global-styles' );  // theme.json generated styles
}, 100 );

Built by Nahnu Plugins

Need something more powerful than a snippet?

Our commercial plugins go further, built for serious WordPress sites with full support, updates, and documentation included.

Browse All Plugins →

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only