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

---

# WP_Theme_JSON::get_block_selectors( object $block_type, string $root_selector ): array

## In this article

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

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

Returns the selectors metadata for a block.

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

 `$block_type`objectrequired

The block type.

`$root_selector`stringrequired

The block’s root selector.

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

 array The custom selectors set by the block.

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

    ```php
    protected static function get_block_selectors( $block_type, $root_selector ) {
    	if ( ! empty( $block_type->selectors ) ) {
    		return $block_type->selectors;
    	}

    	$selectors = array( 'root' => $root_selector );
    	foreach ( static::BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS as $key => $feature ) {
    		$feature_selector = wp_get_block_css_selector( $block_type, $key );
    		if ( null !== $feature_selector ) {
    			$selectors[ $feature ] = array( 'root' => $feature_selector );
    		}
    	}

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

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

| Uses | Description | 
| [wp_get_block_css_selector()](https://developer.wordpress.org/reference/functions/wp_get_block_css_selector/)`wp-includes/global-styles-and-settings.php` |

Determines the CSS selector for the block type and property provided, returning it if available.

  |

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