Opened 12 years ago
Closed 12 years ago
#28689 closed enhancement (duplicate)
Add a filter to the locate_template() function
| Reported by: | aristath | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Themes | Version: | 4.0 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | template |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Duplicate of #13239 and #14310.