get_page_templates( WP_Post|null $post = null, string $post_type = 'page' )
Gets the page templates available in this theme.
Contents
Parameters 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'
Return Return
(string[]) Array of template file names keyed by the template header name.
More Information 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 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 ) ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
4.7.0 | Added the $post_type parameter. |
1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Output a list of available templates
The following code snippet loops through the available page templates and outputs their template names and the filenames.
Expand full source codeCollapse full source code