diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index ca3d8fabaa9df..b6c8c91b464c0 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -218,14 +218,18 @@ function wp_add_global_styles_for_blocks() { continue; } + $stylesheet_handle = 'global-styles'; if ( isset( $metadata['name'] ) ) { - $block_name = str_replace( 'core/', '', $metadata['name'] ); /* * These block styles are added on block_render. * This hooks inline CSS to them so that they are loaded conditionally * based on whether or not the block is used on the page. */ - wp_add_inline_style( 'wp-block-' . $block_name, $block_css ); + if ( str_starts_with( $metadata['name'], 'core/' ) ) { + $block_name = str_replace( 'core/', '', $metadata['name'] ); + $stylesheet_handle = 'wp-block-' . $block_name; + } + wp_add_inline_style( $stylesheet_handle, $block_css ); } // The likes of block element styles from theme.json do not have $metadata['name'] set. @@ -242,8 +246,11 @@ function ( $item ) { ) ); if ( isset( $result[0] ) ) { - $block_name = str_replace( 'core/', '', $result[0] ); - wp_add_inline_style( 'wp-block-' . $block_name, $block_css ); + if ( str_starts_with( $result[0], 'core/' ) ) { + $block_name = str_replace( 'core/', '', $result[0] ); + $stylesheet_handle = 'wp-block-' . $block_name; + } + wp_add_inline_style( $stylesheet_handle, $block_css ); } } }