2

I'm getting an error on my site regarding "headers already sent":

Warning: Cannot modify header information - headers already sent by (output started at ........./wp-admin/menu-header.php:161) in ....../wp-includes/pluggable.php on line 881

I read the Wordpress FAQ that discusses this, but - as you can see - this error is caused by the Wordpress core (and not even at the end of a file).

Interestingly, I don't get this error on my local machine. Only on my server.

What can I do about this?

I'm running Wordpress 3.4.2

6
  • 2
    Something is messing up your admin menu. Maybe a plugin has registered an options page with broken parameters? Disable all plugins and switch to TwentyEleven. Does it still happen?
    – fuxia
    Oct 17, 2012 at 23:59
  • @toscho - Actually, now that you're saying, I realize that I probably messed it up. I register my page under the admin_menu action hook, and then do a wp_redirect from within that page (wp_redirect is defined in pluggable.php). Is there a different (earlier) hook I should be using instead?
    – Myself
    Oct 18, 2012 at 2:26
  • the hook is correct. Did you exit after wp_redirect? Quoted from the codex "wp_redirect() does not exit automatically and should almost always be followed by exit. " Oct 18, 2012 at 7:43
  • @MridulAggarwal - I sure did exit. Since the error originates in pluggable.php, it's clearly caused by the wp_redirect. It's a pity though that I don't get a stack trace.
    – Myself
    Oct 18, 2012 at 13:07
  • it sometimes happens that the filename that appears on the screen is not where the error originated. Check if you have some output before you call wp_redirect. Even a space before <?php is enough to create an error Oct 18, 2012 at 13:37

1 Answer 1

5

Wordpress provides a way to prevent the header HTML from being rendered, by appending &noheader=true to the url.

That will cause the header HTML to wait for you to call it manually, so that you can do a redirect before that.

To later render the header HTML from your page, you'll have to use this:

if ( isset($_GET['noheader']) ) {
    require_once(ABSPATH . 'wp-admin/admin-header.php');
}

For more information, read this article: WordPress and wp_redirect() function problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.