WordPress at a glance

wp_redirect() WP 1.0

Redirects to another page.

Note: wp_redirect() does not exit automatically, and should almost always be followed by a call to exit;:

wp_redirect( $url );

Exiting can also be selectively manipulated by using wp_redirect() as a conditional in conjunction with the 'wp_redirect' and {@see 'wp_redirect_location'} hooks:

if ( wp_redirect( $url ) ) {
  • Global. true/false. $is_IIS

This is a pluggable function, and it can be replaced from plugin. It means that this function is defined (works) only after all plugins are connected (included), but before this moment the function has not yet been defined... Therefore, you cannot call this and all functions depended on this function directly from a plugin code. It must be called via hook plugins_loaded or later, for example on hook init.

Function replacement (override) — in a plugin you can create a function with the same name, then it will replace this function.

Is the basis for: wp_safe_redirect()
Hooks in function

true/false. False if $location is not provided, true otherwise.


wp_redirect( $location, $status );
$location(string) (required)
The path to redirect to.
Status code to use.
Default: 302

Code of wp redirect: wp-includes/pluggable.php VER 5.0.3

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;

Related Functions

From tag: Supporting (helper utility auxiliary)

More from category: Uncategorized

No comments
    Hello, !     Log In . Register