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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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();
}
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(); }
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
檢視更多 >