将单个块呈现为HTML字符串。

原型

render_block( array $block )

参数

$block (array) (Required) 单个解析的块对象。

返回值

(string)  呈现HTML的字符串。

源文件

路径:wp-includes/blocks.php

<?php
...
function render_block( $block ) {
	global $post;
	$block_type    = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
	$is_dynamic    = $block['blockName'] && null !== $block_type && $block_type->is_dynamic();
	$block_content = '';
	$index         = 0;
	foreach ( $block['innerContent'] as $chunk ) {
		$block_content .= is_string( $chunk ) ? $chunk : render_block( $block['innerBlocks'][ $index++ ] );
	}
	if ( ! is_array( $block['attrs'] ) ) {
		$block['attrs'] = array();
	}
	if ( $is_dynamic ) {
		$global_post   = $post;
		$block_content = $block_type->render( $block['attrs'], $block_content );
		$post          = $global_post;
	}
	/**
	 * Filters the content of a single block.
	 *
	 * @since 5.0.0
	 *
	 * @param string $block_content The block content about to be appended.
	 * @param array  $block         The full block, including name and attributes.
	 */
	return apply_filters( 'render_block', $block_content, $block );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/render_block/