get_page_template_slug( int|WP_Post $post = null )
Get the specific template name for a given post.
Description Description
Parameters Parameters
Return Return
(string|false) Page template filename. Returns an empty string when the default page template is in use. Returns false if the post does not exist.
Source Source
File: wp-includes/post-template.php
function get_page_template_slug( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ! $template || 'default' == $template ) {
return '';
}
return $template;
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Now works with any post type, not just pages. |
| 3.4.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Display the page template filename of the current page: