wpseek.com
A WordPress-centric search engine for devs and theme authors
locate_template › WordPress Function
Since2.7.0
Deprecatedn/a
› locate_template ( $template_names, $load = false, $load_once = true, $args = array() )
Parameters: (4) |
|
Returns: |
|
Defined at: |
|
Codex: | |
Change Log: |
|
Retrieves the name of the highest priority template file that exists.
Searches in the stylesheet directory before the template directory and wp-includes/theme-compat so that themes which inherit from a parent theme can just overload one file.Related Functions: load_template, locate_block_template, get_date_template, get_template, get_block_template
Source
function locate_template( $template_names, $load = false, $load_once = true, $args = array() ) { $stylesheet_path = get_stylesheet_directory(); $template_path = get_template_directory(); $is_child_theme = $stylesheet_path !== $template_path; $located = ''; foreach ( (array) $template_names as $template_name ) { if ( ! $template_name ) { continue; } if ( file_exists( $stylesheet_path . '/' . $template_name ) ) { $located = $stylesheet_path . '/' . $template_name; break; } elseif ( $is_child_theme && file_exists( $template_path . '/' . $template_name ) ) { $located = $template_path . '/' . $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; }