WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/wp redirect

Contents

Description

Redirects the user to a specified absolute URI.

Usage

wp_redirect() does not exit automatically and should almost always be followed by exit.

<?php
wp_redirect( $location, $status );
exit;
?>

Parameters

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

Return Values

(bool|void) 
False if $location is not set, returns nothing otherwise.

Examples

<?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; ?>

Notes

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.

Related

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