Skip to main content
fix syntax error
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

So I would add to the Answer the following:


function foo_function() {
     if ( !empty(locate_template( 'home.php' )) ) {
          // '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
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.

So I would add to the Answer the following:


function foo_function() {
     if ( !empty(locate_template( 'home.php' )) ) {
          // '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.

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.

Source Link
Webord
  • 495
  • 2
  • 9

So I would add to the Answer the following:

function foo_function() {
     if ( !empty(locate_template( 'home.php' )) ) {
          // '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.