Skip to content

Commit 0ca1227

Browse files
committed
Output custom CSS as separate styles in block themes
1 parent 9156dc3 commit 0ca1227

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/js/_enqueues/wp/customize/preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@
639639
* @return {void}
640640
*/
641641
custom_css: function( value ) {
642-
$( '#wp-custom-css' ).text( value );
642+
$( '#wp-custom-css-inline-css' ).text( value );
643643
},
644644

645645
/**

src/wp-includes/script-loader.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,20 +2535,6 @@ function wp_enqueue_global_styles() {
25352535

25362536
$stylesheet = wp_get_global_stylesheet();
25372537

2538-
if ( $is_block_theme ) {
2539-
/*
2540-
* Dequeue the Customizer's custom CSS
2541-
* and add it before the global styles custom CSS.
2542-
*/
2543-
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
2544-
// Get the custom CSS from the Customizer and add it to the global stylesheet.
2545-
$custom_css = wp_get_custom_css();
2546-
$stylesheet .= $custom_css;
2547-
2548-
// Add the global styles custom CSS at the end.
2549-
$stylesheet .= wp_get_global_stylesheet( array( 'custom-css' ) );
2550-
}
2551-
25522538
if ( empty( $stylesheet ) ) {
25532539
return;
25542540
}
@@ -2557,6 +2543,24 @@ function wp_enqueue_global_styles() {
25572543
wp_add_inline_style( 'global-styles', $stylesheet );
25582544
wp_enqueue_style( 'global-styles' );
25592545

2546+
if ( $is_block_theme ) {
2547+
/*
2548+
* Dequeue the Customizer's custom CSS
2549+
* and add it before the global styles custom CSS.
2550+
*/
2551+
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
2552+
$customizer_custom_css = wp_get_custom_css();
2553+
wp_register_style( 'wp-custom-css', false );
2554+
wp_add_inline_style( 'wp-custom-css', $customizer_custom_css );
2555+
wp_enqueue_style( 'wp-custom-css' );
2556+
2557+
// Enqueue the global styles custom CSS.
2558+
$global_styles_custom_css = wp_get_global_stylesheet( array( 'custom-css' ) );
2559+
wp_register_style( 'global-styles-custom-css', false );
2560+
wp_add_inline_style( 'global-styles-custom-css', $global_styles_custom_css );
2561+
wp_enqueue_style( 'global-styles-custom-css' );
2562+
}
2563+
25602564
// Add each block as an inline css.
25612565
wp_add_global_styles_for_blocks();
25622566
}

src/wp-includes/theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ function wp_custom_css_cb() {
19581958
if ( $styles || is_customize_preview() ) :
19591959
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
19601960
?>
1961-
<style<?php echo $type_attr; ?> id="wp-custom-css">
1961+
<style<?php echo $type_attr; ?> id="wp-custom-css-inline-css">
19621962
<?php
19631963
// Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly.
19641964
echo strip_tags( $styles );

0 commit comments

Comments
 (0)