wp_redirect()
是重定向到指定url的wordpress函数,简单地理解就是通过该函数可以实现页面跳转到指定URL地址,并可设置指定的状态码,如301、302等。
函数代码
1 | wp_redirect( string $location, int $status = 302, string $x_redirect_by = 'WordPress' ) |
参数说明:
$location
– 字符串,必选,要重定向到的URL,需要是绝对URL地址,不能是相对地址,默认值为空(该值为空的,返回false)$status
– 整数,可选,跳转时的HTTP状态码,默认为302(临时重定向状态码)$x_redirect_by
– 字符串,可选,执行重定向的应用,默认值为“WordPress”
示例
1 2 3 4 | wp_redirect('https://www.boke8.net/', 301); exit; ?> |
提示:因为wp_redirect()
函数不会自动退出,所以添加了exit
,如果需要继续执行则不需要添加。
函数位置:wp-includes/pluggable.php
wordpress官方文档:https://developer.wordpress.org/reference/functions/wp_redirect/
除非注明,文章均由 博客吧 整理发布,欢迎转载。
转载请注明本文地址:https://www.boke8.net/wordpress-function-wp_redirect.html
如果喜欢,可以:点此订阅本站
想在手机阅读更多Wordpress资讯?下载【香港硅谷】Android应用 