Retrieve the name of the highest priority template file that exists.
Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which inherit from a parent theme can just overload one file.
Signature
locate_template( $template_names, $load = false, $require_once = true )
- template_names
- (string|array) Template file(s) to search for, in order.
- load
- (boolean) If true the template file will be loaded if it is found.
Default:false - require_once
- (boolean) Whether to require_once or require. Default true. Has no effect if $load is false.
Default:true
Return
(string) The template filename if one is located.
Source
function locate_template($template_names, $load = false, $require_once = true ) {
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( !$template_name )
continue;
if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
$located = STYLESHEETPATH . '/' . $template_name;
break;
} else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
$located = TEMPLATEPATH . '/' . $template_name;
break;
}
}
if ( $load && '' != $located )
load_template( $located, $require_once );
return $located;
}
WP Trac GitHub Bitbucket
Link here
-
URL
http://queryposts.com/function/locate_template/ -
HTML
<a href='http://queryposts.com/function/locate_template/'>locate_template()</a> -
Markdown
[locate_template()](http://queryposts.com/function/locate_template/) -
BBCode
[url=http://queryposts.com/function/locate_template/]locate_template()[/url]