wp_redirect
Redirects to another page.
Description
Note:
does not exit automatically, and should almost always be followed by a call to exit;:wp_redirect(…)
Exiting can also be selectively manipulated by using
as a conditional in conjunction with the and hooks:wp_redirect(…)
exit;
Parameters (2)
- 0. $location (string)
- The path to redirect to.
- 1. $status — Optional. (int) =>
302
- Status code to use.
Usage
if ( !function_exists( 'wp_redirect' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } // The path to redirect to. $location = ''; // Status code to use. $status = 302; // NOTICE! Understand what this does before running. $result = wp_redirect($location, $status);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/pluggable.php
- function wp_redirect($location, $status = 302) {
- global $is_IIS;
- /**
- * Filters the redirect location.
- *
- * @since 2.1.0
- *
- * @param string $location The path to redirect to.
- * @param int $status Status code to use.
- */
- $location = apply_filters( 'wp_redirect', $location, $status );
- /**
- * Filters the redirect status code.
- *
- * @since 2.3.0
- *
- * @param int $status Status code to use.
- * @param string $location The path to redirect to.
- */
- $status = apply_filters( 'wp_redirect_status', $status, $location );
- if ( ! $location )
- return false;
- $location = wp_sanitize_redirect($location);
- if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' )
- status_header($status); // This causes problems on IIS and some FastCGI setups
- header("Location: $location", true, $status);
- return true;
- }