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

  1. if ( !function_exists( 'get_page_template_slug' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global $post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_page_template_slug($post); 
  9.  

Defined (1)

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

/wp-includes/post-template.php  
  1. function get_page_template_slug( $post = null ) { 
  2. $post = get_post( $post ); 
  3.  
  4. if ( ! $post ) { 
  5. return false; 
  6.  
  7. $template = get_post_meta( $post->ID, '_wp_page_template', true ); 
  8.  
  9. if ( ! $template || 'default' == $template ) { 
  10. return ''; 
  11.  
  12. return $template;