block_core_heading_render

函数
block_core_heading_render ( $attributes, $content )
参数
  • (array) $attributes Attributes of the block being rendered.
    Required:
  • (string) $content Content of the block being rendered.
    Required:
返回值
  • (string) The content of the block being rendered.
定义位置
相关方法
block_core_gallery_renderblock_core_image_render_lightboxregister_block_core_headingrender_block_core_read_moreblock_core_social_link_get_name
引入
-
弃用
-

为标题区块内容添加 wp-block-heading 类。

例如,以下区块内容:

Hello World

将转换为

Hello World

function block_core_heading_render( $attributes, $content ) {
	if ( ! $content ) {
		return $content;
	}

	$p = new WP_HTML_Tag_Processor( $content );

	$header_tags = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' );
	while ( $p->next_tag() ) {
		if ( in_array( $p->get_tag(), $header_tags, true ) ) {
			$p->add_class( 'wp-block-heading' );
			break;
		}
	}

	return $p->get_updated_html();
}

常见问题

FAQs
查看更多 >