Opened 10 years ago
Closed 10 years ago
#28689 closed enhancement (duplicate)
Add a filter to the locate_template() function
Reported by: | aristath | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | Themes | Keywords: | |
Focuses: | template | Cc: |
Description
Hello everyone!
I was trying to change the location of the template files today and realized that there's no non-hacky way to do this. Sure template redirecting is a way but it's pretty limited and has a lot of drawbacks.
Instead, we could simply add a filter to the locate_template() function.
So instead of this:
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;
}
We could instead add a filter and do it like this:
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 apply_filters( 'locate_template', $located );
}
That would allow us greater flexibility and would be really easy to customize!
Are there any objections or should I just submit a patch for that?
Change History (1)
Note: See
TracTickets for help on using
tickets.
Duplicate of #13239 and #14310.