wp_enqueue_global_styles()
Enqueues the global styles defined via theme.json.
Source
File: wp-includes/script-loader.php
function wp_enqueue_global_styles() { if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { 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 ) && ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && ! is_admin() ); $stylesheet = null; if ( $can_use_cache ) { $cache = get_transient( 'global_styles' ); if ( $cache ) { $stylesheet = $cache; } } if ( null === $stylesheet ) { $settings = get_default_block_editor_settings(); $theme_json = WP_Theme_JSON_Resolver::get_merged_data( $settings ); $stylesheet = $theme_json->get_stylesheet(); if ( $can_use_cache ) { set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS ); } } if ( empty( $stylesheet ) ) { return; } wp_register_style( 'global-styles', false, array(), true, true ); wp_add_inline_style( 'global-styles', $stylesheet ); wp_enqueue_style( 'global-styles' ); }
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles