Script Loader: Load block themes styles in the head section.

Previously, some logic was added to load the global stylesheet in the bottom of `<body>` for classic themes that opted-in into loading individual block styles instead of a single stylesheet for them all. At the time, block themes always loaded the global stylesheet in the `<head>`. When block themes landed in core during WordPress 5.9 this logic wasn’t updated to consider them, hence the global stylesheet loaded in the `<body>` for them. This changeset fixes this.

Props oandregal, aristath.
Fixes #55148.


git-svn-id: https://develop.svn.wordpress.org/trunk@52738 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2022-02-16 10:34:20 +00:00
parent 582f4e7da8
commit 6dc1e0ed3b

View File

@ -2307,7 +2307,9 @@ function wp_common_block_scripts_and_styles() {
* @since 5.8.0
*/
function wp_enqueue_global_styles() {
$separate_assets = wp_should_load_separate_core_block_assets();
$separate_assets = wp_should_load_separate_core_block_assets();
$is_block_theme = wp_is_block_theme();
$is_classic_theme = ! $is_block_theme;
/*
* Global styles should be printed in the head when loading all styles combined.
@ -2315,7 +2317,11 @@ function wp_enqueue_global_styles() {
*
* See https://core.trac.wordpress.org/ticket/53494.
*/
if ( ( ! $separate_assets && doing_action( 'wp_footer' ) ) || ( $separate_assets && doing_action( 'wp_enqueue_scripts' ) ) ) {
if (
( $is_block_theme && doing_action( 'wp_footer' ) ) ||
( $is_classic_theme && doing_action( 'wp_footer' ) && ! $separate_assets ) ||
( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) && $separate_assets )
) {
return;
}