Title: WP_Style_Engine::get_classnames
Published: November 2, 2022
Last modified: May 20, 2026

---

# WP_Style_Engine::get_classnames( string $style_value, array $style_definition ): string[]

## In this article

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

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

Returns classnames, and generates classname(s) from a CSS preset property pattern,
e.g. `var:preset||`.

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

 `$style_value`stringrequired

A single raw style value or CSS preset property from the `$block_styles` array.

`$style_definition`arrayrequired

A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.

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

 string[] An array of CSS classnames, or empty array if there are none.

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

    ```php
    protected static function get_classnames( $style_value, $style_definition ) {
    	if ( empty( $style_value ) ) {
    		return array();
    	}

    	$classnames = array();
    	if ( ! empty( $style_definition['classnames'] ) ) {
    		foreach ( $style_definition['classnames'] as $classname => $property_key ) {
    			if ( true === $property_key ) {
    				$classnames[] = $classname;
    				continue;
    			}

    			$slug = static::get_slug_from_preset_value( $style_value, $property_key );

    			if ( $slug ) {
    				/*
    				 * Right now we expect a classname pattern to be stored in BLOCK_STYLE_DEFINITIONS_METADATA.
    				 * One day, if there are no stored schemata, we could allow custom patterns or
    				 * generate classnames based on other properties
    				 * such as a path or a value or a prefix passed in options.
    				 */
    				$classnames[] = strtr( $classname, array( '$slug' => $slug ) );
    			}
    		}
    	}

    	return $classnames;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/style-engine/class-wp-style-engine.php#L511)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/style-engine/class-wp-style-engine.php#L511-L539)

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

| Version | Description | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_style_engine%2Fget_classnames%2F)
before being able to contribute a note or feedback.