warning-250x166Here’s a very quick information on how to resolve this ever-annoying WordPress issue: Cannot modify header information – headers already sent by [file]… This happens usually when you upgrade a WordPress plugin automatically from the dashboard.

But before that, I’d like to make some justifications why I have to make a post on this one. First, my previous post on How to Resolve WordPress Fatal Error: Allowed Memory Size of 3355444432 bytes exhausted (tried to allocate 30720 bytes) is getting a decent amount of traffic especially when there’s a new WordPress upgrade.

Second, my dashboard tells me a handful of people came to this blog looking for the solution on the WordPress error “cannot modify header information – headers already sent by [file]…” So this post should help you if you came here specifically for that.

Okay, before you lose interest, here’s the solution I got from WordPress.org, but before that, you need to understand why this error occurs “just like a thief in the night.” 🙂

According to WordPress, which is not really a very convincing explanation, is that this is caused by “careless” people messing up some codes. Here’s the snippet from WordPress.org:

It is usually because there are spaces, new lines, or other garbage before an opening <?php tag or after a closing ?> tag, typically in wp-config.php. This could be true about some other file too, so please check the error message, as it will list the specific file name where the error occurred…

So a good way to start is to check your wp-config.php file. In most cases you should be able to resolve this problem. Open your WP-CONFIG.PHP file using a php editor (I suggest you use Notepad++ if all you got now is Notepad or Wordpad – avoid using these as it may mess up your codes even more. Notepadd++ is open source and just search it in Google).

Your WP-CONFIG.PHP typically looks like this:

* The base configurations of the WordPress.
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
* This file is used by the wp-config.php creation script during the
* installation. You don't have to use the web site, you can just copy this file
* to "wp-config.php" and fill in the values.
* @package WordPress

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

.... some more wp-config blah blahs... the below is the last section of wp-config.php

* For developers: WordPress debugging mode.
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
define('WP_DEBUG', false);

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

You need to check if there is a space before the opening tag ‘<?php‘ – in many instances this is okay. Then go down until the last line of the wp-config.php file. You should see either a '?>'tag or 'require_once(ABSPATH . 'wp-settings.php');

Panic Button: Can’t see a ‘?>’ tag at the end? Don’t panic, I already did the “panicking” for you – LOL. Let’s ask WordPress why the hell there’s no ‘?>’ end tag here – but it’s working though so better leave it as it is.

Now place your cursor immediately after the last character – there’s either a ‘>‘ or a ‘;‘ that you’ll see, if something else, okay, your turn now to PANIC.

Placing the cursor immediately after the last character should not be that hard, and note that a space isn’t a character in this case. This means you have to make sure that there is no more space after the last character. To do that, try pressing the “delete” key for 30 hours.

Nahhh, 30 seconds should be enough time to waste here – as if you can do something more productive than doing this in 30 seconds (LOL – that should be another post: List of productive things you can do in 30 seconds flat).

Okay try it, it should work. If not, try to review the specific error message and find some mentions of files in there and fix it using the steps above. But in many cases, looking at the error message will just confuse yourself even more unless you’re a super duper WordPress and PHP geek.

If you ask me what’s the success rate of fixing the WP-CONFIG.PHP – well it’s 90%. 10% of the time I just close my eyes, get some sleep and hope that when I wake up, the plugin developer released another quick update. 🙂

Feel free to leave your comments, funny, corny, violent or otherwise.