函数文档

wp_get_theme_data_custom_templates()

💡 云策文档标注

概述

wp_get_theme_data_custom_templates() 函数用于获取主题通过 theme.json 定义的自定义模板的元数据。它返回一个关联数组,包含模板名称和模板数据。

关键要点

  • 函数返回自定义模板的元数据,基于 theme.json 文件。
  • 返回值是关联数组,键为模板名称,值为包含 "title" 和 "postTypes" 字段的模板数据。
  • 内部调用 WP_Theme_JSON_Resolver::get_theme_data() 来获取主题数据。
  • 该函数在 WordPress 6.4.0 版本中引入。

代码示例

function wp_get_theme_data_custom_templates() {
    return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates();
}

📄 原文内容

Returns the metadata for the custom templates defined by the theme via theme.json.

Return

array Associative array of $template_name => $template_data pairs, with $template_data having “title” and “postTypes” fields.

Source

function wp_get_theme_data_custom_templates() {
	return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates();
}

Changelog

Version Description
6.4.0 Introduced.