The get_comment_delimited_block_content() WordPress PHP function returns the content of a block, including comment delimiters.
Usage
get_comment_delimited_block_content( $block_name, $block_attributes, $block_content );
Parameters
- $block_name (string|null) – Required. Block name. Null if the block name is unknown, e.g. Classic blocks have their name set to null.
- $block_attributes (array) – Required. Block attributes.
- $block_content (string) – Required. Block save content.
More information
See WordPress Developer Resources: get_comment_delimited_block_content
Examples
Getting the content of a paragraph block
This example demonstrates how to get the content of a paragraph block with a custom class.
$block_name = 'core/paragraph'; $block_attributes = array( 'className' => 'my-custom-class' ); $block_content = 'This is a paragraph with a custom class.'; echo get_comment_delimited_block_content( $block_name, $block_attributes, $block_content );
Getting the content of an image block
This example demonstrates how to get the content of an image block with an image URL, alt text, and a custom class.
$block_name = 'core/image'; $block_attributes = array( 'url' => 'https://example.com/image.jpg', 'alt' => 'An example image', 'className' => 'my-image-class' ); $block_content = ''; echo get_comment_delimited_block_content( $block_name, $block_attributes, $block_content );
Getting the content of a heading block
This example demonstrates how to get the content of a heading block with a specific level and content.
$block_name = 'core/heading'; $block_attributes = array( 'level' => 2 ); $block_content = 'This is a level 2 heading'; echo get_comment_delimited_block_content( $block_name, $block_attributes, $block_content );
Getting the content of a list block
This example demonstrates how to get the content of a list block with ordered list type and content.
$block_name = 'core/list'; $block_attributes = array( 'ordered' => true ); $block_content = '<li>Item 1</li><li>Item 2</li>'; echo get_comment_delimited_block_content( $block_name, $block_attributes, $block_content );
Getting the content of a classic block
This example demonstrates how to get the content of a classic block with content.
$block_name = null; $block_attributes = array(); $block_content = 'This is a classic block with some content.'; echo get_comment_delimited_block_content( $block_name, $block_attributes, $block_content );