Skip to content

Commit

Permalink
Move custom CSS enqueuing to gutenberg_enqueue_global_styles
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Feb 19, 2024
1 parent 9b811b6 commit 7424bb0
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions lib/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,12 @@ function gutenberg_enqueue_global_styles() {

// Add each block as an inline css.
gutenberg_add_global_styles_for_blocks();
}
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_global_styles' );
add_action( 'wp_footer', 'gutenberg_enqueue_global_styles', 1 );

/**
* Enqueues the global styles custom css.
*
* @since 6.2.0
*/
function gutenberg_enqueue_global_styles_custom_css() {
if ( ! wp_is_block_theme() ) {
return;
}

/**
* Add the custom CSS for the global styles.
* Before that, dequeue the Customizer's custom CSS
* and add it before the global styles custom CSS.
*/
// Don't enqueue Customizer's custom CSS separately.
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );

Expand All @@ -91,8 +83,30 @@ function gutenberg_enqueue_global_styles_custom_css() {

gutenberg_add_global_styles_block_custom_css();
}
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles_custom_css' );
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_global_styles_custom_css' );
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_global_styles' );
add_action( 'wp_footer', 'gutenberg_enqueue_global_styles', 1 );

/**
* Enqueues the global styles custom css.
*
* @since 6.2.0
*/
function gutenberg_enqueue_global_styles_custom_css() {
_deprecated_function( __FUNCTION__, 'Gutenberg 17.8.0', 'gutenberg_enqueue_global_styles' );
if ( ! wp_is_block_theme() ) {
return;
}

// Don't enqueue Customizer's custom CSS separately.
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );

$custom_css = wp_get_custom_css();
$custom_css .= gutenberg_get_global_styles_custom_css();

if ( ! empty( $custom_css ) ) {
wp_add_inline_style( 'global-styles', $custom_css );
}
}

/**
* Function that enqueues the CSS Custom Properties coming from theme.json.
Expand Down

0 comments on commit 7424bb0

Please sign in to comment.