parse_blocks( string $content )

Parses blocks out of a content string.


Description Description


Parameters Parameters

$content

(string) (Required) Post content.


Top ↑

Return Return

(array) Array of parsed block objects.


Top ↑

Source Source

File: wp-includes/blocks.php

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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Jb Audras

    Example of returned array for a Paragraph block:

    array ( 
    	0 => array ( 
    		'blockName' => 'core/paragraph', 
    		'attrs' => array ( 
    			'textColor' => 'vivid-red', 
    			'backgroundColor' => 'luminous-vivid-amber',
    		), 
    		'innerBlocks' => array (
    			/* Child blocks if they exists (used in Column Block for example) */
    		), 
    		'innerHTML' => 'This is a block content!', 
    		'innerContent' => array (
    			0 => 'This is a block content!',
    		), 
    	),
    )
    

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