get_page_template_slug
Get the specific template name for a given post.
Description
(string|false) get_page_template_slug( (null) $post = null );
Returns (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.
Parameters (1)
- 0. $post — Optional. (null) =>
null
- Post ID or
WP_Post
object. Default is global$post
.
Usage
if ( !function_exists( 'get_page_template_slug' ) ) { require_once ABSPATH . WPINC . '/post-template.php'; } // Optional. Post ID or WP_Post object. Default is global $post. $post = null; // NOTICE! Understand what this does before running. $result = get_page_template_slug($post);
Defined (1)
The function is defined in the following location(s).
- /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;
- }