do_action( 'template_redirect' )
Fires before determining which template to load.
Description Description
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
If you need to remove a template_redirect from within a custom plugin, simply using
remove_action( 'template_redirect', 'function_to_remove' );won’t cut it.As a workaround, what you can do is create a function to hook into template_redirect action earlier and then remove the redirect you are trying to remove.
// remove a template redirect from within a custom plugin. add_action( 'template_redirect', 'remove_my_action', 5 ); function remove_my_action(){ remove_action('template_redirect', 'function_to_remove', 10 ); }Redirect existing pages to other pages:
function custom_redirects() { if ( is_front_page() ) { wp_redirect( home_url( '/dashboard/' ) ); die; } if ( is_page('contact') ) { wp_redirect( home_url( '/new-contact/' ) ); die; } } add_action( 'template_redirect', 'custom_redirects' );Expand full source codeCollapse full source code