wp_apply_custom_classname_support

函式
wp_apply_custom_classname_support ( $block_type, $block_attributes )
Access
Private
引數
  • (WP_Block_Type) $block_type Block Type.
    Required:
  • (array) $block_attributes Block attributes.
    Required:
返回值
  • (array) Block CSS classes and inline styles.
定義位置
相關方法
wp_apply_generated_classname_supportwp_register_custom_classname_supportwp_apply_colors_supportwp_apply_alignment_supportwp_apply_spacing_support
引入
5.6.0
棄用
-

wp_apply_custom_classname_support: 這是一個用來給HTML元素應用自定義類名的函式。它接受一個HTML字串和一個classname引數作為輸入,並返回應用了classname的修改後的HTML字串。

將自定義的類名新增到輸出中。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_apply_custom_classname_support( $block_type, $block_attributes ) {
$has_custom_classname_support = block_has_support( $block_type, array( 'customClassName' ), true );
$attributes = array();
if ( $has_custom_classname_support ) {
$has_custom_classnames = array_key_exists( 'className', $block_attributes );
if ( $has_custom_classnames ) {
$attributes['class'] = $block_attributes['className'];
}
}
return $attributes;
}
function wp_apply_custom_classname_support( $block_type, $block_attributes ) { $has_custom_classname_support = block_has_support( $block_type, array( 'customClassName' ), true ); $attributes = array(); if ( $has_custom_classname_support ) { $has_custom_classnames = array_key_exists( 'className', $block_attributes ); if ( $has_custom_classnames ) { $attributes['class'] = $block_attributes['className']; } } return $attributes; }
function wp_apply_custom_classname_support( $block_type, $block_attributes ) {
	$has_custom_classname_support = block_has_support( $block_type, array( 'customClassName' ), true );
	$attributes                   = array();
	if ( $has_custom_classname_support ) {
		$has_custom_classnames = array_key_exists( 'className', $block_attributes );

		if ( $has_custom_classnames ) {
			$attributes['class'] = $block_attributes['className'];
		}
	}

	return $attributes;
}

常見問題

FAQs
檢視更多 >