inject_ignored_hooked_blocks_metadata_attributes()wp-includes/block-template-utils.php | Inject ignoredHookedBlocks metadata attributes into a template or template part.
|
WP_Block_Patterns_Registry::prepare_content()wp-includes/class-wp-block-patterns-registry.php | Prepares the content of a block pattern. If hooked blocks are registered, they get injected into the pattern, when they met the defined criteria.
|
wp_get_post_content_block_attributes()wp-includes/block-editor.php | Retrieves Post Content block attributes from the current post template.
|
wp_generate_block_templates_export_file()wp-includes/block-template-utils.php | Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file.
|
_build_block_template_result_from_file()wp-includes/block-template-utils.php | Builds a unified template object based on a theme file.
|
_build_block_template_result_from_post()wp-includes/block-template-utils.php | Builds a unified template object based a post Object.
|
_inject_theme_attribute_in_block_template_content()wp-includes/deprecated.php | Parses wp_template content and injects the active theme’s stylesheet as a theme attribute into each wp_template_part
|
_remove_theme_attribute_in_block_template_content()wp-includes/deprecated.php | Parses a block template and removes the theme attribute from each template part.
|
WP_Widget_Block::get_dynamic_classname()wp-includes/widgets/class-wp-widget-block.php | Calculates the classname to use in the block widget’s container HTML.
|
filter_block_content()wp-includes/blocks.php | Filters and sanitizes block content to remove non-allowable HTML from parsed block attribute values.
|
do_blocks()wp-includes/blocks.php | Parses dynamic blocks out of post_content and re-renders them.
|
excerpt_remove_blocks()wp-includes/blocks.php | Parses blocks out of a content string, and renders those appropriate for the excerpt.
|
get_post_galleries()wp-includes/media.php | Retrieves galleries from the passed post’s content.
|
Example using
parse_blocks()
to display a block from a postPlace within The Loop
If used in The Loop it renders the first YouTube video embedded within a post. Can be used with other blocks by assigning their blockName.
Use serialize_blocks() to convert the parsed block back to content.
Example of returned array for a Paragraph block:
As of Gutenberg 7.7, for this input:
the output of
parse_blocks
will be:In case you wish to check if current post content is Gutenberg-blocks or using Classic editor:
If post content is Classic Editor, it has only one block, but
blockName
is empty.$fullContent = get_the_content( $pid ); if ( has_blocks( $fullContent ) ) { doit(); }
orif ( has_blocks( $post ) ) { doit(); }