On this page
get_page_templates( WP_Post|null $post = null, string $post_type = 'page' ): string[]
Gets the page templates available in this theme.
Parameters
$postWP_Post|null Optional-
The post being edited, provided for context.
Default:
null $post_typestring Optional-
Post type to get the templates for. Default
'page'.Default:
'page'
Return
string[] Array of template file names keyed by the template header name.
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.
Source
File: wp-admin/includes/theme.php. View all references
function get_page_templates( $post = null, $post_type = 'page' ) {
return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Theme::get_page_templates() wp-includes/class-wp-theme.php | Returns the theme’s post templates for a given post type. |
| wp_get_theme() wp-includes/theme.php | Gets a WP_Theme object for a theme. |
Used By
| Used By | Description |
|---|---|
| register_and_do_post_meta_boxes() wp-admin/includes/meta-boxes.php | Registers the default post meta boxes, and runs the |
| page_template_dropdown() wp-admin/includes/template.php | Prints out option HTML elements for the page templates drop-down. |
| page_attributes_meta_box() wp-admin/includes/meta-boxes.php | Displays page attributes form fields. |
| WP_Posts_List_Table::inline_edit() wp-admin/includes/class-wp-posts-list-table.php | Outputs the hidden row displayed when inline editing |
| wp_xmlrpc_server::wp_getPageTemplates() wp-includes/class-wp-xmlrpc-server.php | Retrieve page templates. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_page_templates