W3cubDocs

/WordPress

parse_blocks( string $content ): array[]

Parses blocks out of a content string.

Parameters

$contentstringrequired
Post content.

Return

array[] Array of block structures.
  • ...$0 array
    An associative array of a single parsed block object. See WP_Block_Parser_Block.
    • blockName string
      Name of block.
    • attrs array
      Attributes from block comment delimiters.
    • innerBlocks array[]
      List of inner blocks. An array of arrays that have the same structure as this one.
    • innerHTML string
      HTML from inside block comment delimiters.
    • innerContent array
      List of string fragments and null markers where inner blocks were found.

    Source

    function parse_blocks( $content ) {
    	/**
    	 * Filter to allow plugins to replace the server-side block parser.
    	 *
    	 * @since 5.0.0
    	 *
    	 * @param string $parser_class Name of block parser class.
    	 */
    	$parser_class = apply_filters( 'block_parser_class', 'WP_Block_Parser' );
    
    	$parser = new $parser_class();
    	return $parser->parse( $content );
    }
    

    Hooks

    apply_filters( ‘block_parser_class’, string $parser_class )

    Filter to allow plugins to replace the server-side block parser.

    Changelog

    Version Description
    5.0.0 Introduced.

    You must log in before being able to contribute a note or feedback.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/parse_blocks