WordPress fixes part 1 – Warning: Cannot modify header information – headers already sent by…

Just wanted to share this fix – I had this error come up when working on my other blog when I installed my latest theme and could not work out why it was happening. The error message mentioned the functions.php file and pluggable.php file in the error message.

From what I’ve read online, this error is caused by whitespace somewhere in the PHP files noted in the error message. As a precaution I went in and checked every php file in my theme and cleaned any inconsistencies, then checked pluggable.php and got rid of the blank space at the end of the file. Reloaded, still no luck.

I then took another look at my functions.php file, and something occurred to me – I added a php comment field at the top of the file before programming in some stuff in the file, and there was a blank line between the comment php tag and the functions – I removed the comment so it was purely the functions on the first line, and problem fixed!

Previous code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
/*  
Theme Name: RetroOtakuV2
Theme URI: http://www.retro-otaku.com/
Description: Custom theme for my blog.
Version: 2.0
Author: Sean Boden
Author URI: http://www.retro-otaku.com/
*/
?>
 
<?php  
if ( function_exists('register_sidebar') )  
    register_sidebar(array(  
        'before_widget' => '<div class="sidemenu-container" id="%1$s"><div class="sidemenu-top"></div><div class="sidemenu-repeater"><div class="sidemenu-main"><div class="sidemenu-content">',  
        'after_widget' => '</div></div></div><div class="sidemenu-base"></div></div>',  
        'before_title' => '<h2>',  
        'after_title' => '</h2>',  
    ));
?>

New code:

1
2
3
4
5
6
7
8
9
<?php  
if ( function_exists('register_sidebar') )  
    register_sidebar(array(  
        'before_widget' => '<div class="sidemenu-container" id="%1$s"><div class="sidemenu-top"></div><div class="sidemenu-repeater"><div class="sidemenu-main"><div class="sidemenu-content">',  
        'after_widget' => '</div></div></div><div class="sidemenu-base"></div></div>',  
        'before_title' => '<h2>',  
        'after_title' => '</h2>',  
    ));
?>

Incedently, you can also see how I set up the sidenav boxes on my other blog this way too in case you’re interested or want to criticise 😛

While everyone might have different issues, hopefully this’ll help someone else who gets this message – check the files indicated in the error message, and if you’ve added a comment to the top of your file for example (like my functions.php file, where I put the theme details in as a php comment and then had a blank space/line underneath), chop it out, re-upload via FTP, and hopefully your issue will be resolved!

I have another WordPress fix to post in the next couple of days on the blog detailing how I setup the drop-down system in my navigation bar in the page header to style the top nav separately from the drop-down boxes to dynamically insert the dividers to the right of each menu item. Stay tuned!

Share

2 Responses to “WordPress fixes part 1 – Warning: Cannot modify header information – headers already sent by…”

  1. All’s well that ends well. FYI, that problem can only be caused by whitespace outside of PHP tags, so adding comments is technically OK.

  2. Ah cool, thanks for clarifying that Chris, will keep it in mind in future should I break something else in PHP (which is inevitable!!!) and get the same error message 🙂

Companion blogs

Calendar

March 2010
M T W T F S S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031