Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. $blocks = parse_blocks( get_the_content() );
  2. $block_ids = array();
  3.  
  4. function get_block_id( $block ) {
  5. if ( $block['blockName'] !== 'core/heading' ) return;
  6.  
  7. $block_html = $block['innerHTML'];
  8. $id_start = strpos( $block_html, 'id="' ) + 4;
  9.  
  10. if ( $id_start === false ) return;
  11.  
  12. $id_end = strpos( $block_html, '"', $id_start );
  13. $block_id = substr( $block_html, $id_start, $id_end - $id_start );
  14.  
  15. return $block_id;
  16. }
  17.  
  18. foreach( $blocks as $block ) {
  19. $block_id = get_block_id( $block );
  20. if ( $block_id ) array_push ( $block_ids, $block_id );
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement