Title: WP_Theme_JSON::get_stylesheet
Published: July 20, 2021
Last modified: August 20, 2026

---

# WP_Theme_JSON::get_stylesheet( string[] $types = array('variables', 'styles', 'presets'), string[] $origins = null, array $options = array() ): string

## In this article

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

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

Returns the stylesheet that results of processing the theme.json structure this 
object represents.

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

 `$types`string[]optional

Types of styles to load. Will load all by default. It accepts:

 * `variables`: only the CSS Custom Properties for presets & custom ones.
 * `styles`: only the styles section in theme.json.
 * `presets`: only the classes for the presets.
 * `base-layout-styles`: only the base layout styles. Deprecated in 7.0.0.
 * `custom-css`: only the custom CSS.

Default:`array('variables', 'styles', 'presets')`

`$origins`string[]optional

A list of origins to include. By default it includes VALID_ORIGINS.

Default:`null`

`$options`arrayoptional

An array of options for now used for internal purposes only (may change without 
notice).

 * `scope` string
 * Makes sure all style are scoped to a given selector
 * `root_selector` string
 * Overwrites and forces a given selector to be used on the root node
 * `skip_root_layout_styles` bool
 * Omits root layout styles from the generated stylesheet. Default false.
 * `base_layout_styles` bool
 * When true generates only base layout styles without alignment rules. Default 
   false.
 * `include_block_style_variations` bool
 * Includes styles for block style variations in the generated stylesheet. Default
   false.

Default:`array()`

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

 string The resulting stylesheet.

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

    ```php
    public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null, $options = array() ) {
    	if ( null === $origins ) {
    		$origins = static::VALID_ORIGINS;
    	}

    	if ( is_string( $types ) ) {
    		// Dispatch error and map old arguments to new ones.
    		_deprecated_argument( __FUNCTION__, '5.9.0' );
    		if ( 'block_styles' === $types ) {
    			$types = array( 'styles', 'presets' );
    		} elseif ( 'css_variables' === $types ) {
    			$types = array( 'variables' );
    		} else {
    			$types = array( 'variables', 'styles', 'presets' );
    		}
    	}

    	$blocks_metadata = static::get_blocks_metadata();
    	$style_nodes     = static::get_style_nodes( $this->theme_json, $blocks_metadata, $options );
    	$setting_nodes   = static::get_setting_nodes( $this->theme_json, $blocks_metadata );

    	$root_style_key    = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $style_nodes, 'selector' ), true );
    	$root_settings_key = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $setting_nodes, 'selector' ), true );

    	if ( ! empty( $options['scope'] ) ) {
    		foreach ( $setting_nodes as &$node ) {
    			$node['selector'] = static::scope_selector( $options['scope'], $node['selector'] );
    		}
    		foreach ( $style_nodes as &$node ) {
    			$node = static::scope_style_node_selectors( $options['scope'], $node );
    		}
    		unset( $node );
    	}

    	if ( ! empty( $options['root_selector'] ) ) {
    		if ( false !== $root_settings_key ) {
    			$setting_nodes[ $root_settings_key ]['selector'] = $options['root_selector'];
    		}
    		if ( false !== $root_style_key ) {
    			$style_nodes[ $root_style_key ]['selector'] = $options['root_selector'];
    		}
    	}

    	$stylesheet = '';

    	if ( in_array( 'variables', $types, true ) ) {
    		$stylesheet .= $this->get_css_variables( $setting_nodes, $origins );
    	}

    	if ( in_array( 'styles', $types, true ) ) {
    		if ( false !== $root_style_key && empty( $options['skip_root_layout_styles'] ) ) {
    			$stylesheet .= $this->get_root_layout_rules( $style_nodes[ $root_style_key ]['selector'], $style_nodes[ $root_style_key ], $options );
    		}
    		$stylesheet .= $this->get_block_classes( $style_nodes );
    	}

    	if ( in_array( 'presets', $types, true ) ) {
    		$stylesheet .= $this->get_preset_classes( $setting_nodes, $origins );
    	}

    	// Load the custom CSS last so it has the highest specificity.
    	if ( in_array( 'custom-css', $types, true ) ) {
    		// Add the global styles root CSS.
    		$stylesheet .= _wp_array_get( $this->theme_json, array( 'styles', 'css' ) );
    	}

    	return $stylesheet;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-theme-json.php#L1968)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-theme-json.php#L1968-L2035)

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

| Uses | Description | 
| [WP_Theme_JSON::get_root_layout_rules()](https://developer.wordpress.org/reference/classes/wp_theme_json/get_root_layout_rules/)`wp-includes/class-wp-theme-json.php` |

Outputs the CSS for layout rules on the root.

  | 
| [WP_Theme_JSON::get_block_classes()](https://developer.wordpress.org/reference/classes/wp_theme_json/get_block_classes/)`wp-includes/class-wp-theme-json.php` |

Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet.

  | 
| [WP_Theme_JSON::get_preset_classes()](https://developer.wordpress.org/reference/classes/wp_theme_json/get_preset_classes/)`wp-includes/class-wp-theme-json.php` |

Creates new rulesets as classes for each preset value such as:

  | 
| [WP_Theme_JSON::get_css_variables()](https://developer.wordpress.org/reference/classes/wp_theme_json/get_css_variables/)`wp-includes/class-wp-theme-json.php` |

Converts each styles section into a list of rulesets to be appended to the stylesheet.

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

Accesses an array in depth based on a path of keys.

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

Marks a function argument as deprecated and inform when it has been used.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/WP_Theme_JSON/get_stylesheet/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/WP_Theme_JSON/get_stylesheet/?output_format=md#)

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

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Deprecated `'base-layout-styles'` type; added `base_layout_styles` option for classic themes. | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Added boolean `skip_root_layout_styles` and `include_block_style_variations` options to control styles output as desired. | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Add fallback layout styles for Post Template when block gap support isn’t available. | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Removed the `$type` parameter, added the `$types` and `$origins` parameters. | 
| [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%2Fclasses%2Fwp_theme_json%2Fget_stylesheet%2F)
before being able to contribute a note or feedback.