Check if a page template is active – WordPress

Add the below given code in to your functions.php

global $wpdb;

$templateQry = “select meta_key from $wpdb->postmeta where meta_key like ‘_wp_page_template’ and meta_value like ‘Template1′”;
$result = $wpdb->query($templateQry);
if ($result) {
echo “page Template1 is active”
} else {
echo “page Template1 is not active”
}

Leave a Reply

Your email address will not be published. Required fields are marked *