WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a native function to check if a theme a template file. For instance, if a theme is not using the 'home.php' file, then execute some code...

share|improve this question
up vote 5 down vote accepted

So I would add to the Answer the following:

function foo_function() {
    $located = locate_template( 'home.php' );
     if ( !empty( $located ) ) {
          // 'home.php' found in Theme, do something
add_action('init', 'foo_function');
// remember to change both of the parameters above, first one for where you want the
// action to happen and the second one the name of the function declared

As @Chip Bennett, said it will check both TEMPLATEPATH and STYLESHEETPATH, but I would append the code to a hook instead of just putting it in the functions.php file.

But's up to you.

share|improve this answer
I'm gonna definitly use it with a hook. I needed the function, because, i'm working on a options panel for my theme framework, that provide layout choices based on available templates. – Wok Apr 20 '11 at 17:35

Any reason locate_template() (Codex ref) wouldn't work?

if ( '' != locate_template( 'home.php' ) ) {
     // 'home.php' found in Theme, do something

Note that locate_template() will check both TEMPLATEPATH and STYLESHEETPATH, so it works for both a stand-alone Theme and a Child Theme.

share|improve this answer
Thanks Chip...much appreciated, i'm gonna give Webord the points, seems he needs it more then you :-P. Your awesome in this corner of Wordpress world. I've learned a lot from all your comments. – Wok Apr 20 '11 at 17:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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