do_action( 'template_redirect' )
Fires before determining which template to load.
More Information
- This action hook executes just before WordPress determines which template page to load. It is a good hook to use if you need to do a redirect with full knowledge of the content that has been queried.
-
Loading a different template is not a good use of this action hook. If you include another template and then use
exit()
(ordie()
), no subsequent template_redirect hooks will be run, which could break the site’s functionality. Instead, use thetemplate_include
filter hook to return the path to the new template you want to use. This will allow an alternative template to be used without interfering with the WordPress loading process.
Source
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/hooks/template_redirect