I’m trying to check whether the page.php template is being used or not. I’ve tried is_page_template( 'page.php' ) but it doesn’t work.

I also can’t use is_page() because I only want to do something when page.php is used, and not when some other custom Page template is used.

Please let me know about this and thanks!

Edit: Should have mentioned earlier that I have a file called common-options.php which is getting included in almost all the templates (like index.php, page.php, single.php and page_blog.php), in this file I’m trying to do the check with the following code:

if ( is_page_template( 'page.php' ) ) {
    echo "success!";
}

But it’s not working when I open a page that is using the “Default Template”.

7 s
7

I actually ran into the same problem myself and my solution was this code:

if(basename(get_page_template()) === 'page.php'){

}

basename(get_page_template()) gets the filename of the page template (according to https://codex.wordpress.org/Function_Reference/get_page_template) and we then check if it is equal to 'page.php'

Leave a Reply

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