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

---

# WP_Theme_JSON::compute_theme_vars( array $settings ): array

## In this article

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

Given an array of settings, extracts the CSS Custom Properties for the custom values
and adds them to the $declarations array following the format:

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_theme_vars/?output_format=md#description)󠁿

array( ‘name’ => ‘property_name’, ‘value’ => ‘property_value, )

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

 `$settings`arrayrequired

Settings to process.

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

 array The modified $declarations.

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

    ```php
    protected static function compute_theme_vars( $settings ) {
    	$declarations  = array();
    	$custom_values = $settings['custom'] ?? array();
    	$css_vars      = static::flatten_tree( $custom_values );
    	foreach ( $css_vars as $key => $value ) {
    		$declarations[] = array(
    			'name'  => '--wp--custom--' . $key,
    			'value' => $value,
    		);
    	}

    	return $declarations;
    }
    ```

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

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/compute_theme_vars/?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%2Fclasses%2Fwp_theme_json%2Fcompute_theme_vars%2F)
before being able to contribute a note or feedback.