Languages: English • Español • Italiano • 日本語 (Add your language)
Retrieve the name of the highest priority template file that exists, optionally loading that file.
Searches STYLESHEETPATH before TEMPLATEPATH, so themes which inherit from a parent can overload one file.
<?php locate_template( $template_names, $load, $require_once ) ?>
Load a specific template part based on the current pagename:
if (locate_template( array( 'content-' . $pageName . '.php' ) ) != '') { // yep, load the page template get_template_part('content', $pageName); } else { // nope, load the content the_content(); }
Since: 2.7.0
locate_template() is located in wp-includes/template.php
.