Which hook should be used to add an action containing a redirect?

I want to build a plugin that grabs certain url params from the query string to build a new query string for the same page. I’m following the excellent the Professional WordPress Plugin Development book, but I’m not sure which hook to use for this action. Here is my action function:

add_action( 'init', 'tccl_redirect' );
function tccl_redirect() {
    header ( "Location: http://www.mysite.com/$mypage?$newparam=$newvalue" );
?>

Which hooks are suitable for header redirects?

3

Like kaiser answered template_redirect hook is indeed appropriate for redirects.

Also you should use wp_redirect() function, rather than setting header.

Leave a Comment