get_page_templates

Get the Page Templates available in this theme.

Description

(array) get_page_templates( (constant) $post = null, (string) $post_type = 'page' ); 

Returns (array)

Key is the template name, value is the filename of the template

Parameters (2)

0. $post — Optional. (constant) => null
The post being edited, provided for context.
1. $post_type — Optional. (string) => 'page'
Post type to get the templates for. Default page..

Usage

  1. if ( !function_exists( 'get_page_templates' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/theme.php'; 
  3.  
  4. // Optional. The post being edited, provided for context. 
  5. $post = null; 
  6.  
  7. // Optional. Post type to get the templates for. Default 'page'. 
  8. $post_type = 'page'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_page_templates($post, $post_type); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/theme.php  
  1. function get_page_templates( $post = null, $post_type = 'page' ) { 
  2. return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );