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

---

# WP_Theme_JSON::get_property_value( array $styles, array $path, array $theme_json = null ): string|array

## In this article

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

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

Returns the style property for the given path.

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

It also converts references to a path to the value stored at that location, e.g.
{“
ref”: “style.color.background” } => “#fff”.

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

 `$styles`arrayrequired

Styles subtree.

`$path`arrayrequired

Which property to process.

`$theme_json`arrayoptional

Theme JSON array.

Default:`null`

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

 string|array Style property value.

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

    ```php
    protected static function get_property_value( $styles, $path, $theme_json = null ) {
    	$value = _wp_array_get( $styles, $path, '' );

    	if ( '' === $value || null === $value ) {
    		// No need to process the value further.
    		return '';
    	}

    	/*
    	 * This converts references to a path to the value at that path
    	 * where the value is an array with a "ref" key, pointing to a path.
    	 * For example: { "ref": "style.color.background" } => "#fff".
    	 * In the case of backgroundImage, if both a ref and a URL are present in the value,
    	 * the URL takes precedence and the ref is ignored.
    	 */
    	if ( is_array( $value ) && isset( $value['ref'] ) ) {
    		$value_path = explode( '.', $value['ref'] );
    		$ref_value  = _wp_array_get( $theme_json, $value_path );
    		// Background Image refs can refer to a string or an array containing a URL string.
    		$ref_value_url = $ref_value['url'] ?? null;
    		// Only use the ref value if we find anything.
    		if ( ! empty( $ref_value ) && ( is_string( $ref_value ) || is_string( $ref_value_url ) ) ) {
    			$value = $ref_value;
    		}

    		if ( is_array( $ref_value ) && isset( $ref_value['ref'] ) ) {
    			$path_string      = json_encode( $path );
    			$ref_value_string = json_encode( $ref_value );
    			_doing_it_wrong(
    				'get_property_value',
    				sprintf(
    					/* translators: 1: theme.json, 2: Value name, 3: Value path, 4: Another value name. */
    					__( 'Your %1$s file uses a dynamic value (%2$s) for the path at %3$s. However, the value at %3$s is also a dynamic value (pointing to %4$s) and pointing to another dynamic value is not supported. Please update %3$s to point directly to %4$s.' ),
    					'theme.json',
    					$ref_value_string,
    					$path_string,
    					$ref_value['ref']
    				),
    				'6.1.0'
    			);
    		}
    	}

    	return $value;
    }
    ```

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

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

| Uses | Description | 
| [_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.

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

Retrieves the translation of $text.

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

Marks something as being incorrectly called.

  |

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

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

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | Added support for background image refs. | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | It no longer converts the internal format “var:`preset|color|secondary`” to the standard form “–wp–preset–color–secondary”.
 This is already done by the sanitize method, so every property will be in the standard form. | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added the `$theme_json` parameter. | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added support for values of array type, which are returned as is. | 
| [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_property_value%2F)
before being able to contribute a note or feedback.