wp_get_block_default_classname

函数
wp_get_block_default_classname ( $block_name )
Access
Private
参数
  • (string) $block_name Block Name.
    Required:
返回值
  • (string) Generated classname.
定义位置
相关方法
wp_get_elements_class_namewp_theme_get_element_class_namewp_get_widget_defaultsget_the_author_lastnameget_block_file_template
引入
5.6.0
弃用
-

wp_get_block_default_classname: 这个函数检索一个块的默认类名。它将块的类型作为参数,并返回一个包含块的默认类名称的字符串。

从一个给定的块名中获取生成的类名。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_block_default_classname( $block_name ) {
// Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature.
// Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (historically used in 'core-embed/').
$classname = 'wp-block-' . preg_replace(
'/^core-/',
'',
str_replace( '/', '-', $block_name )
);
/**
* Filters the default block className for server rendered blocks.
*
* @since 5.6.0
*
* @param string $class_name The current applied classname.
* @param string $block_name The block name.
*/
$classname = apply_filters( 'block_default_classname', $classname, $block_name );
return $classname;
}
function wp_get_block_default_classname( $block_name ) { // Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature. // Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (historically used in 'core-embed/'). $classname = 'wp-block-' . preg_replace( '/^core-/', '', str_replace( '/', '-', $block_name ) ); /** * Filters the default block className for server rendered blocks. * * @since 5.6.0 * * @param string $class_name The current applied classname. * @param string $block_name The block name. */ $classname = apply_filters( 'block_default_classname', $classname, $block_name ); return $classname; }
function wp_get_block_default_classname( $block_name ) {
	// Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature.
	// Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (historically used in 'core-embed/').
	$classname = 'wp-block-' . preg_replace(
		'/^core-/',
		'',
		str_replace( '/', '-', $block_name )
	);

	/**
	 * Filters the default block className for server rendered blocks.
	 *
	 * @since 5.6.0
	 *
	 * @param string     $class_name The current applied classname.
	 * @param string     $block_name The block name.
	 */
	$classname = apply_filters( 'block_default_classname', $classname, $block_name );

	return $classname;
}

常见问题

FAQs
查看更多 >