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
if ( !function_exists( 'get_page_template' ) ) { require_once ABSPATH . WPINC . '/template.php'; } // NOTICE! Understand what this does before running. $result = get_page_template();
Defined (1)
The function is defined in the following location(s).
- /wp-includes/template.php
- function get_page_template() {
- $id = get_queried_object_id();
- $template = get_page_template_slug();
- $pagename = get_query_var('pagename');
- if ( ! $pagename && $id ) {
- // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
- $post = get_queried_object();
- if ( $post )
- $pagename = $post->post_name;
- }
- $templates = array();
- if ( $template && 0 === validate_file( $template ) )
- $templates[] = $template;
- if ( $pagename ) {
- $pagename_decoded = urldecode( $pagename );
- if ( $pagename_decoded !== $pagename ) {
- $templates[] = "page-{$pagename_decoded}.php";
- }
- $templates[] = "page-$pagename.php";
- }
- if ( $id )
- $templates[] = "page-$id.php";
- $templates[] = 'page.php';
- return get_query_template( 'page', $templates );
- }