Yasha from Russia asks for guidance!
Hi I was searching on ways to resolve get header error in WP and saw your posts, which helped a chap with his website. I am a total beginner and having a nightmare with a divi template I am trying to upload. I have tried a ton of solutions on line and nothing worked. I would be grateful if you could provide me with some guidance. Unfortunately I am not in a position to pay you, but should our path cross I would be happy to offer you a few fine Belgian beers. Thank you in advance
I don’t drink beer (I can’t stand fizzy drinks, I know, it’s tragic).
I have to preface this with the honest truth. I hate Divi Templates. I’ve reached out to them under my company hat a couple times, never heard back, but I cannot stand their theme because of the first line in header.php
for every single theme I’ve ever seen from them.
<?php if ( ! isset( $_SESSION ) ) session_start(); ?>
Pardon me while I rage flip a table.
Why do I hate this? Sessions aren’t friends with caching. A session is used to store information for a user and have it accessible across all the pages of your website. Cool, right? The problem is a session is also saying “This user gets unique content and should have a unique experience.”
Which kinda tells caching, and specifically Varnish caching, to take a long walk. WPEngine doesn’t allow you to use them because of that.
But all that aside, how do you debug that Headers Already Sent?
- Turn on
wp_debug
- Read the error
- Kill the plugin (or theme) causing it
I hate to say it’s that simple, but it usually is.
Warning: Cannot modify header information - headers already sent by (output started at /example.com/wp-content/themes/applesororanges/functions.php:60) in /example.com/wp-includes/pluggable.php on line 962
That error means the problem is in the theme applesororanges and you check by swapping themes.
When you get around to these, it’s a bit messier:
Warning: Cannot modify header information - headers already sent by (output started at /example.com/wp-includes/functions.php:3560) in /example.com/wp-includes/pluggable.php on line 962
The bit in ‘output started at…’ is a wp-includes folder! It’s unlikely core has bad code, so here you have to turn off all the plugins and switch to a default theme. There’s a reason that’s the way we debug, by the way. It’s hands down the fastest way to see if it’s you or not.
If turning off all the plugins fixed it, great. Now turn them back on, one at a time, until you break it again.
Remember! Sometimes it’s the combination of the plugins and theme that caused the problem, so be ready to pick a second best theme or plugin.
Comments
2 responses to “Mailbag: Headers Already Sent”
Sometimes it’s as simple as a PHP file having a closing
?>
tag that has spaces after.Removing the closing tag can fix it, if that’s the problem. The closing tag is optional for PHP files.
@Andy Fragen: The weirdest one I ever saw was one that did this:
<?php
// Lots of code
?>
<?php
// More code
For some reason, the weird space in the middle caused PHP 5.3 to throw a fit.