diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 98d0719cd24a9..5975e4fe9852f 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -2738,10 +2738,14 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt return $nodes; } - $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; $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 ) {