block_core_navigation_filter_out_empty_blocks()
Filter out empty "null" blocks from the block list. 'parse_blocks' includes a null block with '\n\n' as the content when it encounters whitespace. This is not a bug but rather how the parser is designed.
No Hooks.
Returns
Array. the normalized parsed blocks.
Usage
block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
- $parsed_blocks(array) (required)
- the parsed blocks to be normalized.
Changelog
| Since 5.9.0 | Introduced. |
block_core_navigation_filter_out_empty_blocks() block core navigation filter out empty blocks code WP 6.9.1
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
$filtered = array_filter(
$parsed_blocks,
static function ( $block ) {
return isset( $block['blockName'] );
}
);
// Reset keys.
return array_values( $filtered );
}