_add_block_template_info

函式
_add_block_template_info ( $template_item )
Access
Private
引數
  • (array) $template_item Template to add information to (requires 'slug' field).
    Required:
返回值
  • (array) Template item.
定義位置
相關方法
_add_block_template_part_area_info_get_block_template_file_get_block_templates_fileslocate_block_templateget_block_template
引入
5.9.0
棄用
-

add_block_template_info: 這個動作用於新增塊模板的資訊,如名稱、類別和描述。這些資訊被塊編輯器用來在模板選擇器中顯示該模板。

試圖向模板專案新增自定義模板資訊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _add_block_template_info( $template_item ) {
if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
return $template_item;
}
$theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates();
if ( isset( $theme_data[ $template_item['slug'] ] ) ) {
$template_item['title'] = $theme_data[ $template_item['slug'] ]['title'];
$template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes'];
}
return $template_item;
}
function _add_block_template_info( $template_item ) { if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { return $template_item; } $theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates(); if ( isset( $theme_data[ $template_item['slug'] ] ) ) { $template_item['title'] = $theme_data[ $template_item['slug'] ]['title']; $template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes']; } return $template_item; }
function _add_block_template_info( $template_item ) {
	if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
		return $template_item;
	}

	$theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates();
	if ( isset( $theme_data[ $template_item['slug'] ] ) ) {
		$template_item['title']     = $theme_data[ $template_item['slug'] ]['title'];
		$template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes'];
	}

	return $template_item;
}

常見問題

FAQs
檢視更多 >