Get Name of the Current Template File
Get Name of the Current Template File. In wordpress, you need to edit certain posts and pages based on the page template and ID of the template.
Here I have small code snippet to get the current page, page template. Before getting into the page template work, we need current page or Post ID to query the current post template. Let’s begin with code.
<?php $kv_post_id = get_the_ID(); ?>
The above one get the current post or page id, with the help of the function we are going to get the page template.
global $wp_query; $template_name = get_post_meta( $kv_post_id, '_wp_page_template', true );
This how, you can retrieve the page template name and its details.
Any doubts and problem in implementation, drop your comment below.