WP_Theme_JSON::get_custom_templates()publicWP 5.9.0

Returns the page templates of the active theme.

{} It's a method of the class: WP_Theme_JSON{}

No Hooks.

Return

Array.

Usage

$WP_Theme_JSON = new WP_Theme_JSON();
$WP_Theme_JSON->get_custom_templates();

Changelog

Since 5.9.0 Introduced.

Code of WP_Theme_JSON::get_custom_templates() WP 6.0

public function get_custom_templates() {
	$custom_templates = array();
	if ( ! isset( $this->theme_json['customTemplates'] ) || ! is_array( $this->theme_json['customTemplates'] ) ) {
		return $custom_templates;
	}

	foreach ( $this->theme_json['customTemplates'] as $item ) {
		if ( isset( $item['name'] ) ) {
			$custom_templates[ $item['name'] ] = array(
				'title'     => isset( $item['title'] ) ? $item['title'] : '',
				'postTypes' => isset( $item['postTypes'] ) ? $item['postTypes'] : array( 'page' ),
			);
		}
	}
	return $custom_templates;
}