is_page_template not working

is_page_template() will only tell you if the page is using a custom page template. Meaning a template that was created by adding the Template Name: comment to the file and selecting it from the Template dropdown, as described here. The function works by checking the post meta for which template was selected.

If you have created a page template using the slug or ID using the method described here, which you appear to have, then the template being used is not stored in meta, so won’t be picked up by the is_page_template() function.

If you want to know the filename of the current template being used, regardless of whether it’s a custom template or not, you can use the global $template variable:

global $template;

if ( basename( $template ) === 'page-47.php' ) {

}

Leave a Comment