1

In the wordpress admin dashboard, on the pages tab, when you edit the page, there's a section called "Page Attributes". One of the options is "Templates", which opens a drop-down list of templates available.

Is it actually possible to find which template name corresponds to which file in the theme editor without looking through every single file in the theme editor?

1

I'm not entirely certain I understand what you mean but whenever a Page Template is set WordPress also sets postmeta with a specific key and value. The key is called _wp_page_template and the value holds the template location relative to the theme. So you could do this:

$pages_with_templates = new WP_Query( array(
    'post_type'         => 'page',
    'posts_per_page'    => 20,
    'meta_key'          => '_wp_page_template',
) );

This will return a list of pages that have templates, you could narrow it down even more by supplying a value:

$pages_with_this_template = new WP_Query( array(
    'post_type'         => 'page',
    'posts_per_page'    => 20,
    'meta_key'          => '_wp_page_template',
    'meta_value'        => 'template-fullwidth.php',
) );

Now, when I said relative to the theme I mean that if you are using a sub-directory such as:
theme-name/page-templates/template-fullwidth.php the postmeta value will hold:
pages-templates/template-fullwidth.php.

There's also a conditional to test if the current page is using a specific template:

if( is_page_template( 'template-fullwidth.php' ) ) { ... }

Finally, if you're using the body_class() function - WordPress will assign a specific class based on the template to the body tag which you could target if you feel so inclined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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