Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/wp-includes/block-supports/custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,21 @@ function wp_render_custom_css_support_styles( $parsed_block ) {

if ( ! empty( $processed_css ) ) {
/*
* Register and add inline style for block custom CSS.
* The style depends on global-styles to ensure custom CSS loads after
* and can override global styles.
* Track which class names have already had their CSS enqueued to prevent
* duplicate styles when the same block is rendered multiple times inside
* a Query Loop (render_block_data fires once per loop iteration).
*/
wp_register_style( 'wp-block-custom-css', false, array( 'global-styles' ) );
wp_add_inline_style( 'wp-block-custom-css', $processed_css );
$handle = 'wp-block-custom-css';
if ( ! wp_style_is( $handle, 'registered' ) ) {
wp_register_style( $handle, false, array( 'global-styles' ) );
}
$after_styles = wp_styles()->get_data( $handle, 'after' );
if ( ! is_array( $after_styles ) ) {
$after_styles = array();
}
if ( ! in_array( $processed_css, $after_styles, true ) ) {
wp_add_inline_style( $handle, $processed_css );
}
}

return $parsed_block;
Expand Down
Loading