Title: WP_Theme_JSON::get_block_style_variation_feature_selector
Published: August 20, 2026

---

# WP_Theme_JSON::get_block_style_variation_feature_selector( array $style_variation, string $feature_selector ): string

## In this article

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

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

Applies a block style variation class to a feature selector.

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

Feature selectors can target a different element than the block’s root selector.
For example, the Button block’s root selector targets the inner link, while its 
dimensions width selector targets the outer wrapper. Apply the variation class directly
to the selector that will receive the declarations instead of deriving it by subtracting
the root selector from the feature selector.

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

 `$style_variation`arrayrequired

Style variation metadata.

`$feature_selector`stringrequired

CSS selector for the feature.

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

 string Feature selector with block style variation selector added.

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

    ```php
    protected static function get_block_style_variation_feature_selector( $style_variation, $feature_selector ) {
    	$variation_path = $style_variation['path'] ?? array();
    	$variation_name = $style_variation['name'] ?? ( is_array( $variation_path ) ? end( $variation_path ) : null );

    	if ( ! $variation_name ) {
    		return $style_variation['selector'] ?? $feature_selector;
    	}

    	$variation_class = ".is-style-$variation_name";
    	$selector_parts  = static::split_selector_list( $feature_selector );
    	$selector_parts  = array_map(
    		static function ( $selector ) use ( $variation_class ) {
    			$prefix = $variation_class . ' ';

    			if ( str_starts_with( $selector, $prefix ) ) {
    				return substr( $selector, strlen( $prefix ) );
    			}

    			return $selector;
    		},
    		$selector_parts
    	);

    	return static::get_block_style_variation_selector(
    		$variation_name,
    		implode( ', ', $selector_parts )
    	);
    }
    ```

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

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

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