Tag Archives: wordpress

Using template_redirect to load a different template? No!

Loading a different template is NOT proper use of this hook! Use the template_include hook to return the path to the new template you want to use. 

template_redirect is great hook to use when you need to redirect users elsewhere after WordPress has made it’s main query and all objects are available. However, since no output has been sent to the browser at this point it provides a lot of flexibility.

Below is an example of how WordPress’s template_redirect hook can be used. It’s a function I used on project to publicly disable certain post type archives while development and content were still in progress.