wp_enqueue_global_styles()
- Since
- 5.8.0
- Source
wp-includes/script-loader.php:2515
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–61
- 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 63.
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 · 19 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 && doing_action() | 19–21 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action() |
$is_block_theme && empty($stylesheet) | 20 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), add_filter(), wp_get_global_stylesheet() |
$is_block_theme && empty($stylesheet) | 24–26 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), add_filter(), wp_get_global_stylesheet() |
!$is_block_theme | 24–25 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), doing_action() |
!$is_block_theme && empty($stylesheet) | 29–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 && empty($stylesheet) | 33 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), wp_get_global_stylesheet() |
!doing_action() && !$is_block_theme && empty($stylesheet) | 33–35 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet() |
$is_block_theme && !empty($stylesheet) | 33 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), 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) | 37–39 | 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(), wp_get_global_stylesheet() |
$is_block_theme && !empty($stylesheet) | 37–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) | 42–44 | 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(), wp_get_global_stylesheet() |
7 further outcomes, up to 61 instructions
!$is_block_theme && !empty($stylesheet) | 42–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() |
!doing_action() && !$is_block_theme && empty($stylesheet) | 46–48 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), wp_get_global_stylesheet() |
$is_block_theme && !empty($stylesheet) | 46 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
!doing_action() && !$is_block_theme && !empty($stylesheet) | 46–48 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), 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) | 50–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(), 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) | 55–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(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
!doing_action() && !$is_block_theme && !empty($stylesheet) | 59–61 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), doing_action(), doing_action(), doing_action(), add_filter(), wp_get_global_stylesheet(), remove_action(), wp_get_custom_css(), wp_get_global_stylesheet(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style(), wp_add_global_styles_for_blocks() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 63 instructions, 13–61 executed per call, 10 branches. The work does not change between versions.
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 · 11
- 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.
- 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.
- 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.
- 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 the default. * The footer should only be used for classic themes when loading assets on demand is enabled. * * See https://core.trac.wordpress.org/ticket/53494 and https://core.trac.wordpress.org/ticket/61965. */ if ( ( $is_block_theme && doing_action( 'wp_footer' ) ) || ( $is_classic_theme && doing_action( 'wp_footer' ) && ! $assets_on_demand ) || ( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) && $assets_on_demand ) ) { 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(); 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. $custom_css = wp_get_custom_css(); $stylesheet .= $custom_css; // Add the global styles custom CSS at the end. $stylesheet .= wp_get_global_stylesheet( array( 'custom-css' ) ); } if ( empty( $stylesheet ) ) { return; } wp_register_style( 'global-styles', false ); wp_add_inline_style( 'global-styles', $stylesheet ); wp_enqueue_style( 'global-styles' ); // Add each block as an inline css. wp_add_global_styles_for_blocks();}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 6.8.8 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.