This is a handy little wrapper around wp_redirect I use in functions.php. Most of the time when using wp_redirct I want PHP to exit, so thats what the following function does, and while we’re at it why not throw in the ability to accept a post ID or a uri for the location.
/** * A handy wrapper to wp_redirect which exits after calling wp_redirect. * $location can be a url or a post id. * * @param string|integer * @return bool False if $location is not set */ function wptf_redirect( $location = '', $status = 302 ) { $permalink = false; if( is_int( $location ) ) { $permalink = true; $location = get_permalink( $location ); } if ( ! $location ) { return false; } if( ! $permalink ) { $location = ltrim( $location, '/' ); $location = '/'.trailingslashit( $location ); $location = get_bloginfo( 'url' ).$location; } wp_redirect( $location, $status ); exit; }