get_page_templates() WordPress Function

The get_page_templates() function is used to retrieve the list of page templates available for the current theme. This function can be used to check if a specific page template is available for the current theme.

get_page_templates( WP_Post|null $post = null, string $post_type = 'page' ) #

Gets the page templates available in this theme.


Parameters

$post

(WP_Post|null)(Optional) The post being edited, provided for context.

Default value: null

$post_type

(string)(Optional) Post type to get the templates for.

Default value: 'page'


Top ↑

Return

(string[]) Array of template file names keyed by the template header name.


Top ↑

More Information

The function searches all the current theme’s template files for the commented “Template Name: name of template”. See also wp_get_theme() and the wp_get_theme()->get_page_templates() method of the WP_Theme class.


Top ↑

Source

File: wp-admin/includes/theme.php

function get_page_templates( $post = null, $post_type = 'page' ) {
	return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Added the $post_type parameter.
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.