get_page_template

Retrieve path of page template in current or parent template.

Description

(string) get_page_template(); 

The hierarchy for this template looks like:

1. .php 2. page-.php 3. page-.php 4. page.php

An example of this is:

1. page-templates/full-width.php 2. page-about.php 3. page-4.php 4. page.php

The template hierarchy is filterable via the hook. The template path is filterable via the hook.

Returns (string)

Full path to page template file.


Usage

  1. if ( !function_exists( 'get_page_template' ) ) { 
  2. require_once ABSPATH . WPINC . '/template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_page_template(); 
  7.  

Defined (1)

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

/wp-includes/template.php  
  1. function get_page_template() { 
  2. $template = get_page_template_slug(); 
  3. $pagename = get_query_var('pagename'); 
  4.  
  5. if ( ! $pagename && $id ) { 
  6. // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object 
  7. $post = get_queried_object(); 
  8. if ( $post ) 
  9. $pagename = $post->post_name; 
  10.  
  11. $templates = array(); 
  12. if ( $template && 0 === validate_file( $template ) ) 
  13. $templates[] = $template; 
  14. if ( $pagename ) { 
  15. $pagename_decoded = urldecode( $pagename ); 
  16. if ( $pagename_decoded !== $pagename ) { 
  17. $templates[] = "page-{$pagename_decoded}.php"; 
  18. $templates[] = "page-$pagename.php"; 
  19. if ( $id ) 
  20. $templates[] = "page-$id.php"; 
  21. $templates[] = 'page.php'; 
  22.  
  23. return get_query_template( 'page', $templates );