WordPress uses the get_page_template_slug() function
to get the current page template name. This function returns the page template file name. For example, if you have a template like page-xxx.php
, this function returns page-xxx.php
.
$template_name = get_page_template_slug( get_the_ID() );
// $template_name may contain 'page-xxx.php
This function takes a page ID as an argument and returns the slug of the custom template set for that page. If no custom template is set, it returns an empty string.