From 7ab937d71b238b29408de9f1e52e8ddae59a431b Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 7 Jul 2022 11:43:21 +1000 Subject: [PATCH] The `gutenberg_get_style_nodes` filter has to be registered before we call gutenberg_get_global_stylesheet() otherwise global styles won't filter out the block styles that are later enqueued. --- lib/compat/wordpress-6.1/script-loader.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/compat/wordpress-6.1/script-loader.php b/lib/compat/wordpress-6.1/script-loader.php index 1a33861aaf60b..b3995178431e9 100644 --- a/lib/compat/wordpress-6.1/script-loader.php +++ b/lib/compat/wordpress-6.1/script-loader.php @@ -84,6 +84,13 @@ function gutenberg_enqueue_global_styles() { return; } + /** + * If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally. + * This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block. + * This filter has to be registered before we call gutenberg_get_global_stylesheet(); + */ + add_filter( 'gutenberg_get_style_nodes', 'filter_out_block_nodes', 10, 1 ); + $stylesheet = gutenberg_get_global_stylesheet(); if ( empty( $stylesheet ) ) { return; @@ -93,11 +100,6 @@ function gutenberg_enqueue_global_styles() { wp_add_inline_style( 'global-styles', $stylesheet ); wp_enqueue_style( 'global-styles' ); - /** - * If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally. - * This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block. - */ - add_filter( 'gutenberg_get_style_nodes', 'filter_out_block_nodes' ); // add each block as an inline css. wp_add_global_styles_for_blocks(); }