wp_enqueue_global_styles()
- Since
- 5.8.0
- Source
wp-includes/script-loader.php:2548
Compatibility
- WordPress
- since 5.8.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to wp_enqueue_global_styles() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Moderate
- Scaling
- Constant
- Instructions
- 13–73
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_transient(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 92.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_enqueue_global_styles() - cacheobject cache
wp_cache_get()one call below wp_enqueue_global_styles() - transienttransient
get_transient()one call below wp_enqueue_global_styles()
Further down the call graph this can also reach option, query and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 15 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_enqueue_global_styles() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
doing_action() | 13–15 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action() |
$is_block_theme && empty($stylesheet) | 23–26 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet() |
!$is_block_theme && doing_action() && !has_action() | 23–26 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), has_action() |
!$is_block_theme && empty($stylesheet) | 27–31 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet() |
!$is_block_theme && doing_action() && has_action() | 34–37 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), has_action(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style() |
$is_block_theme && !empty($stylesheet) | 36–39 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
$is_block_theme && empty($stylesheet) | 40–52 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), wp_get_global_stylesheet() |
!$is_block_theme && !empty($stylesheet) | 40–44 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
!$is_block_theme && empty($stylesheet) | 44–57 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), wp_get_global_stylesheet() |
$is_block_theme && is_customize_preview() && empty($stylesheet) | 45–55 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), is_customize_preview(), wp_get_global_stylesheet() |
!$is_block_theme && is_customize_preview() && empty($stylesheet) | 49–60 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), is_customize_preview(), wp_get_global_stylesheet() |
$is_block_theme && !empty($stylesheet) | 53–65 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
3 further outcomes, up to 73 instructions
!$is_block_theme && !empty($stylesheet) | 57–70 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
$is_block_theme && is_customize_preview() && !empty($stylesheet) | 58–68 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), is_customize_preview(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
!$is_block_theme && is_customize_preview() && !empty($stylesheet) | 62–73 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), is_customize_preview(), is_customize_preview(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 92 | 13–73 | 13 | |
| 8.5 | 92 | 13–73 | 13 | |
| 8.4 | 92 | 13–73 | 13 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 98 | 13–79 | 13 | |
| 8.2 | 98 | 13–79 | 13 | |
| 8.1 | 98 | 13–79 | 13 | |
| 7.4 | 98 | 13–79 | 13 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 13
- wp_should_load_block_assets_on_demand()Checks whether block styles should be loaded only on-render.
- wp_is_block_theme()Returns whether the active theme is a block-based theme or not.
- doing_action()Returns whether or not an action hook is currently being processed.
- has_action()Checks if any action has been registered for a hook.
- wp_register_style()Registers a CSS stylesheet.
- wp_add_inline_style()Adds extra CSS styles to a registered stylesheet.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- add_filter()Adds a callback function to a filter hook.
- wp_get_global_stylesheet()Returns the stylesheet resulting of merging core, theme, and user data.
- remove_action()Removes a callback function from an action hook.
- wp_get_custom_css()Fetches the saved Custom CSS content for rendering.
- is_customize_preview()Whether the site is being previewed in the Customizer.
Show all 13
- wp_add_global_styles_for_blocks()Adds global style rules to the inline style for each block.
Source code
function wp_enqueue_global_styles() { $assets_on_demand = wp_should_load_block_assets_on_demand(); $is_block_theme = wp_is_block_theme(); $is_classic_theme = ! $is_block_theme; /** * Global styles should be printed in the HEAD for block themes, or for classic themes when loading assets on * demand is disabled (which is no longer the default since WordPress 6.9). * * @link https://core.trac.wordpress.org/ticket/53494 * @link https://core.trac.wordpress.org/ticket/61965 */ if ( doing_action( 'wp_footer' ) && ( $is_block_theme || ( $is_classic_theme && ! $assets_on_demand ) ) ) { return; } /** * The footer should only be used for classic themes when loading assets on demand is enabled. In WP 6.9 this is the * default with the introduction of hoisting late-printed styles (via {@see wp_load_classic_theme_block_styles_on_demand()}). * So even though the main global styles are not printed here in the HEAD for classic themes with on-demand asset * loading, a placeholder for the global styles is still enqueued. Then when {@see wp_hoist_late_printed_styles()} * processes the output buffer, it can locate the placeholder and inject the global styles from the footer into the * HEAD, replacing the placeholder. * * @link https://core.trac.wordpress.org/ticket/64099 */ if ( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) && $assets_on_demand ) { if ( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ) ) { wp_register_style( 'wp-global-styles-placeholder', false ); wp_add_inline_style( 'wp-global-styles-placeholder', ':root { --wp-internal-comment: "Placeholder for wp_hoist_late_printed_styles() to replace with the global-styles printed at wp_footer." }' ); wp_enqueue_style( 'wp-global-styles-placeholder' ); } return; } /* * If loading the CSS for each block separately, then load the theme.json CSS conditionally. * This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block. * This filter must be registered before calling wp_get_global_stylesheet(); */ add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' ); $stylesheet = wp_get_global_stylesheet(); /* * For block themes, merge Customizer's custom CSS into the global styles stylesheet * before the global styles custom CSS, ensuring proper cascade order. * For classic themes, let the Customizer CSS print separately via wp_custom_css_cb() * at priority 101 in wp_head, preserving its position at the end of the <head>. */ if ( $is_block_theme ) { /* * Dequeue the Customizer's custom CSS * and add it before the global styles custom CSS. */ remove_action( 'wp_head', 'wp_custom_css_cb', 101 ); /* * Get the custom CSS from the Customizer and add it to the global stylesheet. * Always do this in Customizer preview for the sake of live preview since it be empty. */ $custom_css = trim( wp_get_custom_css() ); if ( $custom_css || is_customize_preview() ) { if ( is_customize_preview() ) { /* * When in the Customizer preview, wrap the Custom CSS in milestone comments to allow customize-preview.js * to locate the CSS to replace for live previewing. Make sure that the milestone comments are omitted from * the stored Custom CSS if by chance someone tried to add them, which would be highly unlikely, but it * would break live previewing. */ $before_milestone = '/*BEGIN_CUSTOMIZER_CUSTOM_CSS*/'; $after_milestone = '/*END_CUSTOMIZER_CUSTOM_CSS*/'; $custom_css = str_replace( array( $before_milestone, $after_milestone ), '', $custom_css ); $custom_css = $before_milestone . "\n" . $custom_css . "\n" . $after_milestone;Changelog
Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/script-loader.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.