do_action( 'template_redirect' )
- Since
- 1.5.0
Description
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.
Note: Loading a different template is not a good use of this hook. If you include another template and then use exit() or die(), no subsequent template_redirect hooks will be run, which could break the site’s functionality. Instead, use the 'template_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.
Compatibility
- WordPress
- since 1.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Where this hook fires · 1
wp-includes/template-loader.php:23file scope
Source code
* break the site’s functionality. Instead, use the {@see 'template_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. * * @since 1.5.0 */ do_action( 'template_redirect' );} /** * Filters whether to allow 'HEAD' requests to generate content. * * Provides a significant performance bump by exiting before the pageChangelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.