Get the specific template name for a page or any post type.
<?php get_page_template_slug( $post_id ); ?>
Display the page template filename of the current Page:
<?php echo get_page_template_slug( $post->ID ); ?>
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 )
Since: 3.4.0
get_page_template_slug() is located in wp-includes/post-template.php
get_page_template(), get_page_templates(), is_page_template()