在wordpress重定向期间无法修改标题信息 [英] Cannot modify header information during redirect in wordpress

查看:23
本文介绍了在wordpress重定向期间无法修改标题信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与线程无法修改wordpress中的header信息.不幸的是,那里没有标记为已回答,cpicko 的回答帮助我理解了问题,但我无法解决.

My problem is very similar to the thread Cannot modify header information in wordpress. Unfortunately, it is not marked answered there and cpicko's answer helped me understand the problem but I haven't been able to solve it.

如果订阅者尝试登录他的后端配置文件,我会尝试将他重定向到主页.我想这样做是因为我希望我的网站完全由前端驱动且专业.对于这个 wordpress 在 http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init 上有示例代码.如下图

I am trying to redirect a subscriber to home page if he tries to log in his backend profile. I want to do this because I want my site to be totally front-end driven and professional. For this wordpress has example code on http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init. It is as below

function restrict_admin_with_redirect() {
    if ( ! current_user_can( 'manage_options' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
    wp_redirect( site_url() ); 
    exit;
    }
}
add_action( 'admin_init', 'restrict_admin_with_redirect', 1 );

当我将其粘贴到我的functions.php 中时,它会进行重定向,但在标头后中断并出现以下错误.

When I paste this in my functions.php, it does the redirect but then breaks after header with below error.

"Warning: Cannot modify header information - headers already sent by (output started at /***/wp-content/themes/twentytwelvechild/headerwithquotes.php:15) in /***/wp-includes/pluggable.php on line 1121"

但是这些文件/行根本不是我修改的.它们就像新安装的 wordpress 一样.该示例也与 wordpress 站点中的完全相同.这在我的开发站点中运行良好,但在我迁移到生产时不起作用

But these files/lines are not modifies by me at all. They are just like fresh wordpress install. The example also is exactly like in wordpress site. This works fine in my dev site but doesn't work when I migrate to production

Cpicko 在该线程中提到 javascript 可能会有所帮助.当页面是 wordpress 默认页面而不是网站内置页面时,如何在这种情况下使用 javascript.有人可以帮助我进行此重定向.我真的很感激.

Cpicko mentioned in that thread that javascript might help. How can I use javascript in this scenario when pages are wordpress default pages and not that build in website. Can someone please help me with this redirection. I would really appreciate it.

推荐答案

发生这种情况的原因有多种.几天前,当我尝试向我的 function.php 文件添加一个新函数时,我遇到了这个问题.这是我从谷歌找到的修复

this could happen due to several reasons. i faced to this issue few days ago when i tried to add a new function to my function.php file. here is the fix i found from the google

wp-config.php 问题

wp-config.php issue

1.Open your wp-config.php file with editor to edit it .

2.Remove all the spases before  "<?php " and after the " ?>" symbols

3.If  "?>" symbol is missing just add it at the end of the page.

4.Now save your file and check.

functions.php 问题

functions.php issue

1.Open your functions.php file with editor to edit it  this is located at " wp-    content/themes/your theme name/functions.php". 

2.Remove all the space before  "<?php " and after the " ?>" symbols If  "?>"

3.symbol is missing just add it at the end of the page. Now save your
file and check.

来源:http://www.mytrickpages.com/2013/11/how-to-fix-wordpress-error-cannot-modify-header-information.html

这篇关于在wordpress重定向期间无法修改标题信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆