Title: wp_enqueue_global_styles
Published: July 20, 2021
Last modified: February 24, 2026

---

# wp_enqueue_global_styles()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#wp--skip-link--target)

Enqueues the global styles defined via theme.json.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#source)󠁿

    ```php
    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.
    		 * 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;
    			}
    			$custom_css = "\n" . $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();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/script-loader.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/script-loader.php#L2529)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/script-loader.php#L2529-L2601)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_should_load_block_assets_on_demand()](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/)`wp-includes/script-loader.php` |

Checks whether block styles should be loaded only on-render.

  | 
| [wp_add_global_styles_for_blocks()](https://developer.wordpress.org/reference/functions/wp_add_global_styles_for_blocks/)`wp-includes/global-styles-and-settings.php` |

Adds global style rules to the inline style for each block.

  | 
| [wp_get_global_stylesheet()](https://developer.wordpress.org/reference/functions/wp_get_global_stylesheet/)`wp-includes/global-styles-and-settings.php` |

Returns the stylesheet resulting of merging core, theme, and user data.

  | 
| [wp_is_block_theme()](https://developer.wordpress.org/reference/functions/wp_is_block_theme/)`wp-includes/theme.php` |

Returns whether the active theme is a block-based theme or not.

  | 
| [wp_get_custom_css()](https://developer.wordpress.org/reference/functions/wp_get_custom_css/)`wp-includes/theme.php` |

Fetches the saved Custom CSS content for rendering.

  | 
| [is_customize_preview()](https://developer.wordpress.org/reference/functions/is_customize_preview/)`wp-includes/theme.php` |

Whether the site is being previewed in the Customizer.

  | 
| [wp_register_style()](https://developer.wordpress.org/reference/functions/wp_register_style/)`wp-includes/functions.wp-styles.php` |

Registers a CSS stylesheet.

  | 
| [wp_add_inline_style()](https://developer.wordpress.org/reference/functions/wp_add_inline_style/)`wp-includes/functions.wp-styles.php` |

Adds extra CSS styles to a registered stylesheet.

  | 
| [wp_enqueue_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_style/)`wp-includes/functions.wp-styles.php` |

Enqueues a CSS stylesheet.

  | 
| [remove_action()](https://developer.wordpress.org/reference/functions/remove_action/)`wp-includes/plugin.php` |

Removes a callback function from an action hook.

  | 
| [doing_action()](https://developer.wordpress.org/reference/functions/doing_action/)`wp-includes/plugin.php` |

Returns whether or not an action hook is currently being processed.

  | 
| [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)`wp-includes/plugin.php` |

Adds a callback function to a filter hook.

  |

[Show 7 more](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_enqueue_global_styles%2F)
before being able to contribute a note or feedback.