diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 0295e7d7e2..068ca78b4d 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -554,7 +554,6 @@ add_action( 'wp_default_scripts', 'wp_default_packages' ); add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); -add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); @@ -568,6 +567,10 @@ add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); +// Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494. +add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); +add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); + add_action( 'wp_default_styles', 'wp_default_styles' ); add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 23fe1166f7..d517cac8be 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2267,6 +2267,18 @@ function wp_enqueue_global_styles() { return; } + $separate_assets = wp_should_load_separate_core_block_assets(); + + /* + * Global styles should be printed in the head when loading all styles combined. + * The footer should only be used to print global styles for classic themes with separate core assets enabled. + * + * See https://core.trac.wordpress.org/ticket/53494. + */ + if ( ( ! $separate_assets && doing_action( 'wp_footer' ) ) || ( $separate_assets && doing_action( 'wp_enqueue_scripts' ) ) ) { + return; + } + $can_use_cache = ( ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && diff --git a/wp-includes/version.php b/wp-includes/version.php index 106820d691..a82863950c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51307'; +$wp_version = '5.9-alpha-51309'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.