重定向到另一个页面。
原型
wp_redirect( string $location, int $status = 302 )
描述
注意:wp_redirect()不会自动退出,并且几乎总是会跟着调用退出;
参数
$location
(string)
(Required)
重定向到的路径。
$status
(int)
(Optional)
要使用的状态代码。
返回值
(bool)
如果未提供$ location,则返回false,否则返回true。
源文件
路径:wp-includes/pluggable.php
<?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;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_redirect/