get_allowed_block_template_part_areas()
云策文档标注
概述
get_allowed_block_template_part_areas() 函数返回一个经过过滤的允许模板部件区域值列表。该函数定义了默认的区域定义,并通过 apply_filters 钩子允许开发者自定义。
关键要点
- 函数返回一个数组,包含允许的模板部件区域值,每个区域有 area、label、description、icon 和 area_tag 等属性。
- 默认定义了三个区域:WP_TEMPLATE_PART_AREA_UNCATEGORIZED(通用)、WP_TEMPLATE_PART_AREA_HEADER(页眉)和 WP_TEMPLATE_PART_AREA_FOOTER(页脚)。
- 使用 apply_filters('default_wp_template_part_areas', $default_area_definitions) 钩子,允许通过过滤器修改区域列表。
- 该函数自 WordPress 5.9.0 版本引入,用于支持块主题和模板部件系统。
代码示例
function get_allowed_block_template_part_areas() {
$default_area_definitions = array(
array(
'area' => WP_TEMPLATE_PART_AREA_UNCATEGORIZED,
'label' => _x( 'General', 'template part area' ),
'description' => __(
'General templates often perform a specific role like displaying post content, and are not tied to any particular area.'
),
'icon' => 'layout',
'area_tag' => 'div',
),
array(
'area' => WP_TEMPLATE_PART_AREA_HEADER,
'label' => _x( 'Header', 'template part area' ),
'description' => __(
'The Header template defines a page area that typically contains a title, logo, and main navigation.'
),
'icon' => 'header',
'area_tag' => 'header',
),
array(
'area' => WP_TEMPLATE_PART_AREA_FOOTER,
'label' => _x( 'Footer', 'template part area' ),
'description' => __(
'The Footer template defines a page area that typically contains site credits, social links, or any other combination of blocks.'
),
'icon' => 'footer',
'area_tag' => 'footer',
),
);
return apply_filters( 'default_wp_template_part_areas', $default_area_definitions );
}
原文内容
Returns a filtered list of allowed area values for template parts.
User Contributed Notes
You must log in before being able to contribute a note or feedback.