If I run the following query on the WordPress database, I get a list of templates:

select distinct(meta_value) from wp_postmeta where meta_key='_wp_page_template';

The templates that come back are things like default and templates/page-fullwidth.php and my-template.php. With the exception of default which I assume is a special case, these are clearly relative filenames. The trouble is, I know they're not all relative to the same directory!

So how can I find out where exactly where each template exists in the filing system?

  • 1
    They should be relative to the active theme directory. Default would be page.php. So in your above case it would be /theme-name/templates/page-fullwidth.php
    – Howdy_McGee
    Commented Mar 18, 2016 at 14:22
  • Thanks @Howdy_McGee, but some of my templates are added by plugins, so they don't all live beneath the theme directory.
    – IpsRich
    Commented Mar 18, 2016 at 15:06
  • 1
    _wp_page_template is specifically for the Page Attributes template dropdown menu. If plugins are indeed adding templates to the menu that are outside of the theme directory, you need to determine by what mechanism the plugin is intercepting that value and properly loading the templates. There is no mechanism built into core that allows that without modification to the template loading process.
    – Milo
    Commented Mar 18, 2016 at 16:51
  • Thanks @Milo. That has put me on the right track. I inherited the plugins that create templates, and I see now that they have code to "trick" WordPress into thinking they're real templates. There's a template_include filter that checks the template and returns the actual filename if the template belongs to the plugin.
    – IpsRich
    Commented Mar 21, 2016 at 9:17

1 Answer 1


Unfortunately there is no way to do this. In the end it is nothing more but a meta field. It can come from the current theme, and old theme that doesn't even exist any more or a plugin. Since 4.4.0 it can even be anything - it doesn't even need to be a filename.

Sorry to tell you, but you can't have what you're asking for.

  • Thanks. But where does it say it can be anything? The page you linked defines $page_templates as "(array) Array of page templates. Keys are filenames, values are translated names." (It says keys are filenames.)
    – IpsRich
    Commented Mar 21, 2016 at 14:39
  • Yes that is the way it was until 4.4. If you look at the actual code you can see that with the mentioned filter you can alter the array in any way you want.
    – kraftner
    Commented Mar 22, 2016 at 21:21

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.