How to Solve WordPress Error: Warning: Cannot modify header information – headers already sent by()

Nur . Posted in Errors, How-To 709 Views

Sometime when you are trying to modify you theme file or try to write an code entry, just in case you left empty space in your theme file  and chances are you have messed up your wp-config.php leaving some unnecessary spaces inside.

You get a warning message on your browser that says:

Warning: Cannot modify header information - headers already sent by (output started at

If you ever run across this error (or warning) in your WordPress with this message, Here is the simple solution for that:

Reason and Solution:

The reason behind this error may be there are spaces, new lines, or other garbage before an opening <?php tag or after a closing ?> tag, typically in wp-config.php. This error can be occur due to some other files too. So carefully check the error massage because it will list the specific file name. To overcome this error please follow the steps below.

  1. Download the wp-config.php or file mentioned in the error message.
  2. Open that file with your favourite editora or in plain text editor.
  3. The only thing you need to do is to clear all spaces before “<?php” and after “?>

In case above given  solution do not solve your problem, than checkout these guide lines.

Check the encoding of the file and save .php file under ASCII format . If the file is encoded as UTF-8 with BOM (Byte Order Mark), the BOM is seen as a character which starts the output, so make sure the first 3 bytes Byte Order Mark is deleted.

Other issues that might cause that error are you may be using function wp_ redirect() for redirection or trying to use a header redirect after the header that error message will show up. So better use javascript redirection if needed.

There is well explained interpretation about this error message on WordPress FAQ_Troubleshooting as follow:

If the error message states: Warning: Cannot modify header information - headers already sent by (output started at /path/blog/wp-config.php:34) in /path/blog/wp-login.php on line 42, then the problem is at line #34 of wp-config.php, not line #42 of wp-login.php. In this scenario, line #42 of wp-login.php is the victim. It is being affected by the excess whitespace at line #34 of wp-config.php.

If the error message states: Warning: Cannot modify header information - headers already sent by (output started at /path/wp-admin/admin-header.php:8) in /path/wp-admin/post.php on line 569, then the problem is at line #8 of admin-header.php, not line #569 of post.php. In this scenario, line #569 of post.php is the victim. It is being affected by the excess whitespace at line #8 of admin-header.php.

At the end I would advice you to make a backup of any files you edit.

Nur

I am a Wordpress, Website Developer and Designer, creator @ WP Arena, Provide Free WordPress consultation and can help to install WordPress in a secure way to small businesses and bloggers.

Free & Professional WordPress Security Service Free & Professional WordPress Security Service

We Love WordPress. WordPress Arena is a place for WordPress Developers and Designers, providing Tips, tricks, tools and resources to build a website or blog on WordPress. We also present The WordPress Showcase for all kind of WordPress Powered Websites.


Copyright © 2014 WP Arena All Rights Reserved

Divi WordPress Theme