Looking through the Wordpress documentation, it says that is_page_template() compares against a "template name", if one is provided.

I have a template stored in page-homepage.php called Homepage:

 * Template Name: Homepage
 * Description: The template for displaying the homepage

And I have some code I wish to run in my functions.php when I'm using that template:

if (is_page_template('Homepage')) { 

But it isn't being triggered when I'm on a page which uses that template.

When I look at the code that Wordpress executes for is_page_template(), it looks like it actually checks for the document name, not the template name...?

function is_page_template( $template = '' ) {

    $page_template = get_page_template_slug( get_queried_object_id() );

    if ( $template == $page_template )
        return true;

In my instance it seems that $page_template is page-homepage.php -- not the template name, like the documentation suggests...?

Am I doing something wrong?

  • Good observation regarding the documentation.
    – birgire
    Commented Sep 8, 2016 at 18:32

2 Answers 2


Your condition should be written like this:

if (is_page_template('path/file.php')) { 
    // Do stuff

I believe the confusion is a result of two things:

  1. The docs refer to "name" ambiguously. Specifying "file name" would make the documentation much more clear.
  2. The code behind is_page_template() shows the get_page_template_slug() function at its core. This function actually returns a file name, not the template slug. https://codex.wordpress.org/Function_Reference/get_page_template_slug

When specifying an argument for the is_page_template() function (as in the example above), the file path is relative to the theme root.

This function will not work inside the loop.

EDIT: an important issue to note here as well. The is_page_template() function will return empty/false if the page is using the default template from the hierarchy. If a custom template is not assigned, you must use another method, such as basename(get_page_template()). See Jacob's answer here for more details: https://wordpress.stackexchange.com/a/328427/45202

  • 2
    It would be nice to have an explanation what path stands for here.
    – birgire
    Commented Sep 8, 2016 at 18:35
  • 1
    Added additional clarification and details on why this can be confusing.
    – jdm2112
    Commented Sep 8, 2016 at 18:45
  • 3
    Wow. A double whammy of confusion. I can understand the docs being a bit ambiguous (although it really should be fixed), but I'm really surprised that get_page_template_slug() doesn't actually return a slug! Commented Sep 9, 2016 at 9:09
  • 1
    This answer contains the "best practice" solution. However, if your page is using the "default template" (but it is actually a Page Template), this answer may interest you.
    – rinogo
    Commented Aug 9, 2018 at 23:12
  • 1
    Thank you, @rinogo. Added a note above as I just ran into this issue, personally, again.
    – jdm2112
    Commented May 11, 2020 at 21:53

I think the best thing to say is, it checks on the FILE name and in your case it would be page-homepage.php. so:

if (is_page_template('page-homepage.php')) { 

Other things to think of is if the template file is actually stored within another folder inside the theme. read more

One more thing, the Template Name: Homepage is genrally whats used to identify the template when creating a page or post.

  • 1
    As another answer points out - it also takes path into consideration. page-templates/page-homepage.php is different than the template in the theme root.
    – Howdy_McGee
    Commented Sep 8, 2016 at 18:31
  • Interesting and something I didnt know, just to confirm, I can store the page templates outside the theme or child theme folder?
    – Malisa
    Commented Sep 8, 2016 at 18:36
  • FYI this one works also on Sage development environment
    – Fred K
    Commented May 13, 2022 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.