Title: wp_get_global_stylesheet
Published: February 3, 2022
Last modified: May 20, 2026

---

# wp_get_global_stylesheet( array $types = array() ): string

## In this article

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

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

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_global_stylesheet/?output_format=md#parameters)󠁿

 `$types`arrayoptional

Types of styles to load.
 See ['WP_Theme_JSON::get_stylesheet'](https://developer.wordpress.org/reference/classes/'WP_Theme_JSON/get_stylesheet'/)
for all valid types. If empty, will load: `'variables'`, `'presets'`, `'styles'`.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_global_stylesheet/?output_format=md#return)󠁿

 string Stylesheet.

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

    ```php
    function wp_get_global_stylesheet( $types = array() ) {
    	/*
    	 * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
    	 * developer's workflow.
    	 */
    	$can_use_cached = empty( $types ) && ! wp_is_development_mode( 'theme' );

    	/*
    	 * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
    	 * @see `wp_cache_add_non_persistent_groups()`.
    	 *
    	 * The rationale for this is to make sure derived data from theme.json
    	 * is always fresh from the potential modifications done via hooks
    	 * that can use dynamic data (modify the stylesheet depending on some option,
    	 * settings depending on user permissions, etc.).
    	 * See some of the existing hooks to modify theme.json behavior:
    	 * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
    	 *
    	 * A different alternative considered was to invalidate the cache upon certain
    	 * events such as options add/update/delete, user meta, etc.
    	 * It was judged not enough, hence this approach.
    	 * @see https://github.com/WordPress/gutenberg/pull/45372
    	 */
    	$cache_group = 'theme_json';
    	$cache_key   = 'wp_get_global_stylesheet';
    	if ( $can_use_cached ) {
    		$cached = wp_cache_get( $cache_key, $cache_group );
    		if ( $cached ) {
    			return $cached;
    		}
    	}

    	$tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( WP_Theme_JSON_Resolver::get_merged_data() );

    	if ( empty( $types ) ) {
    		$types = array( 'variables', 'styles', 'presets' );
    	}

    	/*
    	 * Enable base layout styles only mode for classic themes without theme.json.
    	 * This skips alignment styles that target .wp-site-blocks which is only used by block themes.
    	 */
    	$options = array();
    	if ( ! wp_is_block_theme() && ! wp_theme_has_theme_json() ) {
    		$options['base_layout_styles'] = true;
    	}

    	/*
    	 * If variables are part of the stylesheet, then add them.
    	 * This is so themes without a theme.json still work as before 5.9:
    	 * they can override the default presets.
    	 * See https://core.trac.wordpress.org/ticket/54782
    	 */
    	$styles_variables = '';
    	if ( in_array( 'variables', $types, true ) ) {
    		/*
    		 * Only use the default, theme, and custom origins. Why?
    		 * Because styles for `blocks` origin are added at a later phase
    		 * (i.e. in the render cycle). Here, only the ones in use are rendered.
    		 * @see wp_add_global_styles_for_blocks
    		 */
    		$origins          = array( 'default', 'theme', 'custom' );
    		$styles_variables = $tree->get_stylesheet( array( 'variables' ), $origins, $options );
    		$types            = array_diff( $types, array( 'variables' ) );
    	}

    	/*
    	 * For the remaining types (presets, styles), we do consider origins:
    	 *
    	 * - themes without theme.json: only the classes for the presets defined by core
    	 * - themes with theme.json: the presets and styles classes, both from core and the theme
    	 */
    	$styles_rest = '';
    	if ( ! empty( $types ) ) {
    		/*
    		 * Only use the default, theme, and custom origins. Why?
    		 * Because styles for `blocks` origin are added at a later phase
    		 * (i.e. in the render cycle). Here, only the ones in use are rendered.
    		 * @see wp_add_global_styles_for_blocks
    		 */
    		$origins     = array( 'default', 'theme', 'custom' );
    		$styles_rest = $tree->get_stylesheet( $types, $origins, $options );
    	}

    	$stylesheet = $styles_variables . $styles_rest;
    	if ( $can_use_cached ) {
    		wp_cache_set( $cache_key, $stylesheet, $cache_group );
    	}

    	return $stylesheet;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/global-styles-and-settings.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/global-styles-and-settings.php#L148)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/global-styles-and-settings.php#L148-L238)

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

| Uses | Description | 
| [WP_Theme_JSON_Resolver::resolve_theme_file_uris()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/resolve_theme_file_uris/)`wp-includes/class-wp-theme-json-resolver.php` |

Resolves relative paths in theme.json styles to theme absolute paths and merges them with incoming theme JSON.

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

Checks whether the site is in the given development mode.

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

Checks whether a theme or its parent has a theme.json file.

  | 
| [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_Theme_JSON_Resolver::get_merged_data()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_merged_data/)`wp-includes/class-wp-theme-json-resolver.php` |

Returns the data merged from multiple origins.

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

Saves the data to the cache.

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

Retrieves the cache contents from the cache by key and group.

  |

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

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

Function that enqueues the CSS Custom Properties coming from theme.json.

  | 
| [get_block_editor_settings()](https://developer.wordpress.org/reference/functions/get_block_editor_settings/)`wp-includes/block-editor.php` |

Returns the contextualized block editor settings for a selected editor context.

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

Enqueues the global styles defined via theme.json.

  |

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

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Deprecated `'base-layout-styles'` type; classic themes now receive full styles with layout-specific alignment rules skipped via `base_layout_styles` option. | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Resolves relative paths in theme.json styles to theme absolute paths. | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added `'base-layout-styles'` support. | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |

## User Contributed Notes

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