Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $blocks = parse_blocks( get_the_content() );
- $block_ids = array();
- function get_block_id( $block ) {
- if ( $block['blockName'] !== 'core/heading' ) return;
- $block_html = $block['innerHTML'];
- $id_start = strpos( $block_html, 'id="' ) + 4;
- if ( $id_start === false ) return;
- $id_end = strpos( $block_html, '"', $id_start );
- $block_id = substr( $block_html, $id_start, $id_end - $id_start );
- return $block_id;
- }
- foreach( $blocks as $block ) {
- $block_id = get_block_id( $block );
- if ( $block_id ) array_push ( $block_ids, $block_id );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement