'remove_gutenberg_css', 'title' => 'Remove block editor CSS from frontend', 'desc' => 'Remove block library and global styles from the front end', 'icon' => 'code', 'risk' => 'advanced', 'level' => 'advanced', 'audience' => 'developer', 'priority' => 10, 'benefit' => 'Many classic themes load the full block stylesheet on every page (about 140 KB before compression, about 19 KB compressed, in WordPress 7.1). If your content contains no blocks, that CSS is unused.', 'help' => 'Removes these stylesheets from the front end: wp-block-library, wp-block-library-theme, wc-block-style, global-styles and classic-theme-styles. Do not use it with a block theme (such as Twenty Twenty-Five) or on pages built with blocks: global-styles carries the theme\'s colours, fonts and layout, and blocks lose their styling without these files.', 'before' => 'Block CSS loaded on the front end, even with no blocks in the content', 'after' => 'Block CSS removed from the front end.', 'detect' => function () { // Check if Classic Editor is active or Gutenberg is disabled. $classic = is_plugin_active( 'classic-editor/classic-editor.php' ); $disable_gut = is_plugin_active( 'disable-gutenberg/disable-gutenberg.php' ); $uses_blocks = false; // Sample last 10 posts for block content. $posts = get_posts( array( 'numberposts' => 10, 'post_status' => 'publish', ) ); foreach ( $posts as $p ) { if ( has_blocks( $p ) ) { $uses_blocks = true; break; } } if ( $classic || $disable_gut ) { return array( 'detected' => true, 'message' => 'Classic Editor active — block CSS is unused', 'safe' => true, 'savings' => '~19KB gzipped CSS', ); } if ( ! $uses_blocks ) { return array( 'detected' => true, 'message' => 'No block content found in recent posts', 'safe' => true, 'savings' => '~19KB gzipped CSS', ); } return array( 'detected' => false, 'message' => 'Site uses block content — keep enabled', 'safe' => false, ); }, 'callback' => function () { add_action( 'wp_enqueue_scripts', function () { wp_dequeue_style( 'wp-block-library' ); wp_dequeue_style( 'wp-block-library-theme' ); wp_dequeue_style( 'wc-block-style' ); wp_dequeue_style( 'global-styles' ); wp_dequeue_style( 'classic-theme-styles' ); }, 100 ); }, );