template_redirect
Fires before determining which template to load.
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 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.
Usage
add_action( 'template_redirect', 'wp_kama_template_redirect_action' );
/**
* Function for `template_redirect` action-hook.
*
* @return void
*/
function wp_kama_template_redirect_action(){
// action...
}Changelog
| Since 1.5.0 | Introduced. |
Where the hook is called
In file: /wp-includes/template-loader.php
wp-includes/template-loader.php 23
do_action( 'template_redirect' );
Where the hook is used in WordPress
wp-includes/customize/class-wp-customize-selective-refresh.php 147
add_action( 'template_redirect', array( $this, 'handle_render_partials_request' ) );
wp-includes/default-filters.php 332
add_action( 'template_redirect', 'rest_output_link_header', 11, 0 );
wp-includes/default-filters.php 364
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
wp-includes/default-filters.php 471
add_action( 'template_redirect', 'wp_old_slug_redirect' );
wp-includes/default-filters.php 672
add_action( 'template_redirect', 'redirect_canonical' );
wp-includes/default-filters.php 673
add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
wp-includes/default-filters.php 693
add_action( 'template_redirect', '_wp_admin_bar_init', 0 );
wp-includes/ms-default-filters.php 74
add_action( 'template_redirect', 'maybe_redirect_404' );
wp-includes/sitemaps/class-wp-sitemaps.php 69
add_action( 'template_redirect', array( $this, 'render_sitemaps' ) );