Title: WP_Theme_JSON::get_block_nodes
Published: November 2, 2022
Last modified: February 24, 2026

---

# WP_Theme_JSON::get_block_nodes( array $theme_json, array $selectors = array(), array $options = array() ): array

## In this article

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

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

An internal method to get the block nodes from a theme.json file.

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

 `$theme_json`arrayrequired

The theme.json converted to an array.

`$selectors`arrayoptional

Optional list of selectors per block.

Default:`array()`

`$options`arrayoptional

An array of options for now used for internal purposes only (may change without 
notice).

 * `include_block_style_variations` bool
 * Include nodes for block style variations. Default false.
 * `include_node_paths_only` bool
 * Return only block nodes node paths. Default false.

Default:`array()`

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

 array The block nodes in theme.json.

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

    ```php
    private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) {
    	$nodes = array();

    	if ( ! isset( $theme_json['styles']['blocks'] ) ) {
    		return $nodes;
    	}

    	$include_variations      = $options['include_block_style_variations'] ?? false;
    	$include_node_paths_only = $options['include_node_paths_only'] ?? false;

    	// If only node paths are to be returned, skip selector assignment.
    	if ( ! $include_node_paths_only ) {
    		$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
    	}

    	foreach ( $theme_json['styles']['blocks'] as $name => $node ) {
    		$node_path = array( 'styles', 'blocks', $name );
    		if ( $include_node_paths_only ) {
    			$variation_paths = array();
    			if ( $include_variations && isset( $node['variations'] ) ) {
    				foreach ( $node['variations'] as $variation => $variation_node ) {
    					$variation_paths[] = array(
    						'path' => array( 'styles', 'blocks', $name, 'variations', $variation ),
    					);
    				}
    			}
    			$node = array(
    				'path' => $node_path,
    			);
    			if ( ! empty( $variation_paths ) ) {
    				$node['variations'] = $variation_paths;
    			}
    			$nodes[] = $node;
    		} else {
    			$selector = null;
    			if ( isset( $selectors[ $name ]['selector'] ) ) {
    				$selector = $selectors[ $name ]['selector'];
    			}

    			$duotone_selector = null;
    			if ( isset( $selectors[ $name ]['duotone'] ) ) {
    				$duotone_selector = $selectors[ $name ]['duotone'];
    			}

    			$feature_selectors = null;
    			if ( isset( $selectors[ $name ]['selectors'] ) ) {
    				$feature_selectors = $selectors[ $name ]['selectors'];
    			}

    			$variation_selectors = array();
    			if ( $include_variations && isset( $node['variations'] ) ) {
    				foreach ( $node['variations'] as $variation => $node ) {
    					$variation_selectors[] = array(
    						'path'     => array( 'styles', 'blocks', $name, 'variations', $variation ),
    						'selector' => $selectors[ $name ]['styleVariations'][ $variation ],
    					);
    				}
    			}

    			$nodes[] = array(
    				'name'       => $name,
    				'path'       => $node_path,
    				'selector'   => $selector,
    				'selectors'  => $feature_selectors,
    				'duotone'    => $duotone_selector,
    				'features'   => $feature_selectors,
    				'variations' => $variation_selectors,
    				'css'        => $selector,
    			);
    		}

    		if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) {
    			foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) {
    				$node_path = array( 'styles', 'blocks', $name, 'elements', $element );

    				if ( $include_node_paths_only ) {
    					$nodes[] = array(
    						'path' => $node_path,
    					);
    					continue;
    				}

    				$nodes[] = array(
    					'path'     => $node_path,
    					'selector' => $selectors[ $name ]['elements'][ $element ],
    				);

    				// Handle any pseudo selectors for the element.
    				if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
    					foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
    						if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) {
    							$node_path = array( 'styles', 'blocks', $name, 'elements', $element );

    							$nodes[] = array(
    								'path'     => $node_path,
    								'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ),
    							);
    						}
    					}
    				}
    			}
    		}
    	}

    	return $nodes;
    }
    ```

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

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

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | Added $include_node_paths_only option. | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Added optional selectors and options for generating block nodes. | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Refactored and stabilized selectors API. | 
| [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_theme_json%2Fget_block_nodes%2F)
before being able to contribute a note or feedback.