Title: WP_Theme_JSON::get_block_element_selectors
Published: August 8, 2023
Last modified: February 24, 2026

---

# WP_Theme_JSON::get_block_element_selectors( string $root_selector ): array

## In this article

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

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

Generates all the element selectors for a block.

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

 `$root_selector`stringrequired

The block’s root CSS selector.

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

 array The block’s element selectors.

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

    ```php
    protected static function get_block_element_selectors( $root_selector ) {
    	/*
    	 * Assign defaults, then override those that the block sets by itself.
    	 * If the block selector is compounded, will append the element to each
    	 * individual block selector.
    	 */
    	$block_selectors   = explode( ',', $root_selector );
    	$element_selectors = array();
    	foreach ( static::ELEMENTS as $el_name => $el_selector ) {
    		$element_selector = array();
    		foreach ( $block_selectors as $selector ) {
    			if ( $selector === $el_selector ) {
    				$element_selector = array( $el_selector );
    				break;
    			}
    			$element_selector[] = static::prepend_to_selector( $el_selector, $selector . ' ' );
    		}
    		$element_selectors[ $el_name ] = implode( ',', $element_selector );
    	}

    	return $element_selectors;
    }
    ```

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

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