Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp redirect


Redirects the user to a specified absolute URI.


wp_redirect() does not exit automatically and should almost always be followed by exit. If you are going to use it in page template or any other page make sure to use the function before get_header().

wp_redirect( $location, $status );


(string) (required) The absolute URI which the user will be redirected to.
Default: None
(integer) (optional) The status code to use.
Default: 302

Return Values

False if $location is not set, returns true otherwise.


<?php wp_redirect( home_url() ); exit; ?>

Redirects can also be external, and/or use a "Moved Permanently" code :

<?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>

The code below redirects to the parent post URL which can be used to redirect attachment pages back to the parent.

<?php wp_redirect( get_permalink( $post->post_parent )); exit; ?>


The HTTP/1.1 status code 302 is a temporary redirect. If the page has moved permanently, use the HTTP status code 301.

wp_redirect() is a Pluggable Function

Change Log

  • Since: 1.5.1

Source File

wp_redirect() is located in wp-includes/pluggable.php.


See also index of Function Reference and index of Template Tags.