parse_blocks()
simply returns all blocks found in the post content, so for what you’re trying to get, you could use a function which calls itself recursively like so:
function my_find_heading_blocks( $blocks ) {
$list = array();
foreach ( $blocks as $block ) {
if ( 'core/heading' === $block['blockName'] ) {
// add current item, if it's a heading block
$list[] = $block;
} elseif ( ! empty( $block['innerBlocks'] ) ) {
// or call the function recursively, to find heading blocks in inner blocks
$list = array_merge( $list, my_find_heading_blocks( $block['innerBlocks'] ) );
}
}
return $list;
}
// Sample usage:
$post = get_post();
$blocks = parse_blocks( $post->post_content );
$headings = my_find_heading_blocks( $blocks );
Related Posts:
- Allow excerpt for pages in Gutenberg?
- WordPress Gutenberg Embed Blocks Are Not Responsive
- How to query multiple post types inside Gutenberg options panel?
- Implementing Gutenberg RichText onSplit / onReplace
- Gutenberg moving core blocks between categories
- Reset data when the field is cleared
- Is there a hook or filter yet for Gutenberg Block Editor to not auto-add Noreferrer to links with a target?
- How to remove specific panels in the editor (Gutenberg) when editing a block (via right panel)?
- Is it possible to use to create a “switchable” preview of a Carousel Gutenberg block?
- What is the significance of ‘root’ in getEntityRecords?
- How to Disable Gutenberg & Return to the Classic WordPress Editor Without any Plugins
- Gutenberg default value not saved in json
- Gutenberg default initial values for FocalPointPicker
- Pre-set CSS class into custom block/template
- How to check whether Gutenberg editor is installed or not [duplicate]
- How to align a single Gutenberg block button in WP 5.5.3?
- Is it possible to print the output of a Gunteberg block with no classes?
- How can you reset InnerBlock content to base template?
- Gutenberg Multiple InnerBlocks
- How can we mimic the columns block in Gutenberg to instead be a list?
- How to set Gutenberg preferences programmatically with wp.data.dispatch?
- Dynamic Gutenburg block output echoes in WP Dashboard
- Are gutenberg blocks ideally supposed to look the same in both back-end and front-end?
- How to output child block attributes on a parent block
- Is there a better way to to make async API calls using the @wordpress/data module?
- How can I center Gutenberg buttons on mobile?
- Extend the “core/link” Block Format
- Passing settings from Reusable Block to it’s children
- Gutenberg element: How to usw Rangecontrol with two values to imitate a rangeslider?
- Is there any simple way to remove Gutenberg editor H1 H5 H6 and change the label for the rest H2 H3 H4?
- Deprecated for blocks.getSaveElement
- WordPress filter post content with PHP before editing it in Gutenberg
- Pass PHP vars to gutenberg sidebar
- Suggested image dimensions Gutenberg Hook
- How Add New Button to Gutenberg Editing Toolbar
- How to force gutenberg to reload blocks after saving
- How can I programaticly open Gutenberg
- Update a block template and apply those changes to an existing post/page
- How do you manage the Gutenberg block previews in the admin area?
- Custom block save does not match due to stripped slashes from br tag and added figure tag around images
- How to disable align-wide for specified blocks in Gutenberg
- Deprecated function not working in Gutenberg
- Gutenberg Block checkbox check-unckeck does not work
- WordPress npm run build and start only outputs wp-scripts start but does nothing
- Gutenberg get index of gutenberg innerblock
- Custom Endpoint API based on attribute gutenberg block
- Add button to Block toolbar: toggleFormat is undefined
- In a block transform, how do I insert innerBlocks?
- What is the name of the user capability to read a reusable block?
- Gutenberg – Prevent Column Nesting in the Visual Editor
- How to remove whitespaces from source of posts created through WordPress Gutenberg editor
- Gutenberg blocks (block editor) with get_the_excerpt and get_the_content, using ACF
- Basic use of useState
- Gutenburg: Remove border of selected block
- Sort Posts by Sticky then by Latest date using the Latest Posts Block
- Unwanted white space next to inputs added within `PluginDocumentSettingPanel` using “
- apiFetch() returns infinite requests
- ToolbarDropdownMenu component missing from @wordpress/scripts package
- Gutenberg Custom Block Not Validating – Ideas?
- Gutenberg dynamic block render_callback gives null for $post
- Editing HTML structure of Gutenberg layout recent post?
- How to add srcdoc attribute to YouTube oEmbed in Gutenberg oEmbed Block
- Pass props / function to InnerBlocks
- Categories in Gutenberg
- Block editor: content resets to the previous state in “Edit as HTML” by clicking somewhere outside of the editing window
- Possible to add the title of a custom gutenberg block to the edit screen?
- Post Format Link using Guttenberg
- How do I hide the UI for specific Gutenberg Blocks?
- Creating a Dynamic InnerBlock that updates depending on state
- Resizing images on page
- When to use removeEditorPanel()
- Error After Installing Gutenberg plugin (caused by attempt to stop WP from stripping out tags)
- Block validation failed – escaped HTML in content save
- Add media dynamically on gutenberg block
- FormTokenField passing objects to value property
- Trying to save an object into post meta with wp.data.dispatch(‘core/editor’).editpost
- Core Block Columns Attributes for Innerblocks Template
- WordPress – Increase number of posts in “Add Link” dialogue
- Is it possible to consume context from a parent block and update it from within a child block?
- Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined
- How to register multiple blocks
- WordPress “HTML editor” which doesn’t trash hand-coded HTML?
- How to force package.json to create build some files?
- How to edit post meta by post ID in Gutenberg
- How to modify array of object in Gutenberg (block/editor)?
- fetch more than 100 records in block editor API call
- How can I deprecate an old version of my custom Gutenberg block, but keep the new version?
- register_block_type – no block available in block editor
- Block development: how to bump version on generated css files?
- Full Site Editing (FSE) – How do I display no results with wp:query?
- How can I disable fontSizes of the Paragraph block inside the Quote block with theme.json?
- Categories, tags and thumbnails panels are not visible in the Block editor’s post menu
- How to translate multiple blocks within one plugin
- Dealing with unknown option ‘–variant’ when setting up a block environment
- How to disable the Code Editor in Gutenberg?
- Localising a Block
- WordPress.org UI: How do you make Bulleted/Numbered Lists indent by default?
- Unable to remove panels
- Is there a way to delete “wp-block-group__inner-container” div from the gutenberg editor view?
- Gallery Block in template, validation fails after adding column number