wp_render_typography_support

函数
wp_render_typography_support ( $block_content, $block )
参数
  • (string) $block_content Rendered block content.
    Required:
  • (array) $block Block object.
    Required:
返回值
  • (string) Filtered block content.
定义位置
相关方法
wp_register_typography_supportwp_apply_typography_supportwp_render_duotone_supportwp_render_layout_support_flagwp_render_elements_support
引入
6.1.0
弃用
-

wp_render_typography_support: 这个函数为主题增加了对排版的支持。这允许主题开发者为他们的主题定义字体、字体大小和其他排版设置。

将排版样式/内容渲染到块包装中。

function wp_render_typography_support( $block_content, $block ) {
	if ( ! isset( $block['attrs']['style']['typography']['fontSize'] ) ) {
		return $block_content;
	}

	$custom_font_size = $block['attrs']['style']['typography']['fontSize'];
	$fluid_font_size  = wp_get_typography_font_size_value( array( 'size' => $custom_font_size ) );

	/*
	 * Checks that $fluid_font_size does not match $custom_font_size,
	 * which means it's been mutated by the fluid font size functions.
	 */
	if ( ! empty( $fluid_font_size ) && $fluid_font_size !== $custom_font_size ) {
		// Replaces the first instance of `font-size:$custom_font_size` with `font-size:$fluid_font_size`.
		return preg_replace( '/font-sizes*:s*' . preg_quote( $custom_font_size, '/' ) . 's*;?/', 'font-size:' . esc_attr( $fluid_font_size ) . ';', $block_content, 1 );
	}

	return $block_content;
}

常见问题

FAQs
查看更多 >