locate_template() – Retrieves the name of the highest priority template file that exists.
You appear to be a bot. Output may be restricted
Description
Retrieves the name of the highest priority template file that exists.
Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat so that themes which inherit from a parent theme can just overload one file.
Usage
$string = locate_template( $template_names, $load, $load_once, $args );
Parameters
- $template_names
- ( string|array ) required – Template file(s) to search for, in order.
- $load
- ( bool ) optional – If true the template file will be loaded if it is found.
- $load_once
- ( bool ) optional default: 1 – Whether to require_once or require. Has no effect if
$load
is false. Default true. - $args
- ( array ) optional – Optional. Additional arguments passed to the template. Default empty array.
Returns
string The template filename if one is located.
Source
File name: wordpress/wp-includes/template.php
Lines:
1 to 25 of 25
function locate_template( $template_names, $load = false, $load_once = true, $args = array() ) { $located = ''; foreach ( (array) $template_names as $template_name ) { if ( ! $template_name ) { continue; } if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { $located = STYLESHEETPATH . '/' . $template_name; break; } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { $located = TEMPLATEPATH . '/' . $template_name; break; } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { $located = ABSPATH . WPINC . '/theme-compat/' . $template_name; break; } } if ( $load && '' !== $located ) { load_template( $located, $load_once, $args ); } return $located; }