当前位置:网站首页 > 教程 > Wordpress教程 > WordPress 使用 wp_redirect 函数出现 Warning: Cannot modify header information – headers already sent
WordPress 使用 wp_redirect 函数出现 Warning: Cannot modify header information – headers already sent


最近更新主题的时候,使用了 wp_redirect() 函数来做一个页面跳转,没想到出现了“Warning: Cannot modify header information – headers already sent”的错误提示:
搜索了下,php中使用重定向跳转时,“Warning: Cannot modify header information – headers already sent by (output started at…”是常见的错误提醒,出现该错误的原因是跳转函数前有包括回车、空格、换行的输出,解决方法是使用ob_start()函数打开缓冲区,使用跳转前的输入进入缓冲区而不会立即输出,避免这个错误提醒。
如果是 wordpress 使用 wp_redirect() 函数导致的这个问题,在当前主题的 functions.php 文件中添加以下函数即可:
1 2 3 4 5 6 7 8 | /** * 解决 wp_redirect()导致的 Warning: Cannot modify header information 问题 * https://www.wpdaxue.com/wp_redirect-Cannot-modify-header-information.html */ function cmp_do_output_buffer() { ob_start(); } add_action('init', 'cmp_do_output_buffer'); |
如果大家还有其他解决办法,欢迎和我们一起分享。
参考资料:
http://www.boke8.net/wordpress-cannot-modify-header-information.html
http://stackoverflow.com/questions/7381661/cannot-modify-header-information-headers-already-sent-by-wordpress-issue#answer-7461813
- 最新文章
-
- phpcms v9无法更新url
- phpcms注册会员操作失败
- phpcms怎么修改模板
- phpcms添加内容报500错误的原因及解决方法
- linux服务器下phpcms提示hash数据验证失败的解决方法
- phpcms与phpsso通信失败的解决方法
- phpcms上传图片提示服务器安全认证错误的原因及解决方法
- phpcms v9更新栏目缓存失败的原因及解决方法
- phpcms v9后台登录提示验证码错误
- phpcms可以做什么?
- phpcms v9安装失败
- phpcms会员登录失败
- phpcms前台js获取不到cookie用户信息
- phpcms控制器不存在
- phpcms v9 php7可以运行吗
- phpcms js乱码怎么解决
- phpcms提示服务器安全认证错误
- phpcms php.ini在哪里
- phpcms phpsso验证码错误
- phpcms v9参数传递错误
- 热门文章
- 热门tag
- 随机tag