Title: WP_Theme_JSON::resolve_variables
Published: August 8, 2023
Last modified: August 20, 2026

---

# WP_Theme_JSON::resolve_variables( WP_Theme_JSON $theme_json ): 󠀁[WP_Theme_JSON](https://developer.wordpress.org/reference/classes/wp_theme_json/)󠁿

## In this article

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

Resolves the values of CSS variables in the given styles.

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

 `$theme_json`[WP_Theme_JSON](https://developer.wordpress.org/reference/classes/wp_theme_json/)
required

The theme json resolver.

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

 [WP_Theme_JSON](https://developer.wordpress.org/reference/classes/wp_theme_json/)
The $theme_json with resolved variables.

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

    ```php
    public static function resolve_variables( $theme_json ) {
    	$settings    = $theme_json->get_settings();
    	$styles      = $theme_json->get_raw_data()['styles'];
    	$preset_vars = static::compute_preset_vars( $settings, static::VALID_ORIGINS );
    	$theme_vars  = static::compute_theme_vars( $settings );
    	$vars        = array_reduce(
    		array_merge( $preset_vars, $theme_vars ),
    		function ( $carry, $item ) {
    			$name                    = $item['name'];
    			$carry[ "var({$name})" ] = $item['value'];
    			return $carry;
    		},
    		array()
    	);

    	$theme_json->theme_json['styles'] = self::convert_variables_to_value( $styles, $vars );
    	return $theme_json;
    }
    ```

[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#L5838)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-theme-json.php#L5838-L5855)

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

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

Replaces CSS variables with their values in place.

  |

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

Gets the styles resulting of merging core, theme, and user data.

  |

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

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.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%2Fresolve_variables%2F)
before being able to contribute a note or feedback.