WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get page template slug

Description

Get the specific template name for a page or any post type.

Usage

 <?php get_page_template_slug$post_id ); ?> 

Parameters

$post_id
(integer) (optional) The page ID to check.
Default: The current post, when used in the The Loop.

Return Values

(string/bool) 
Returns page template filename. Returns an empty string when the default page template is in use. Returns false if the post is not a page.

Examples

Display the page template filename of the current Page:

<?php echo get_page_template_slug( $post->ID ); ?>

Notes

The filename of a Page's assigned custom template is stored as the value of a Custom Field with a key named '_wp_page_template' (in the wp_postmeta database table). If the template is stored in a Theme's subdirectory (or a Parent Theme's subdirectory of a Child Theme), the value of the wp_postmeta is both the folder and file names, e.g.:

my-templates/my-custom-template.php

The function get_page_template_slug() returns an empty string when the value of '_wp_page_template' is either empty or 'default'.

Custom fields starting with an underscore do not display in the Edit screen's Custom Fields module. To retrieve a Page's custom template metadata, you can also use:

get_post_meta( $post->ID, '_wp_page_template', true )

Change Log

Since: 3.4.0

Source File

get_page_template_slug() is located in wp-includes/post-template.php

Related

get_page_template(), get_page_templates(), is_page_template()

See also index of Function Reference and index of Template Tags.