WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Cannot modify header information error – functions.php

[Resolved] Cannot modify header information error – functions.php

  • I am getting a cannot modify header information error on my functions.php, more specifically a file it’s including (which is not the issue).

    Warning: Cannot modify header information - headers already sent by (output started at /home/yc/domains/yc.keytoe.nl/public_html/wp-content/themes/yourconnector/inc/metaboxes.php:6) in /home/yc/domains/yc.keytoe.nl/public_html/wp-includes/pluggable.php on line 881

    Metaboxes.php is my metabox file, where I have all my code for just that. Everything works fine except when trying to save anything, I get a blank page. The save is succesful but I have to manually go back to wp-admin and that obviously isn’t how it’s supposed to work.

    My metaboxes.php code is:

    <?
    // --- METABOX CREATE --- //
    add_action('admin_init', 'page_spec_meta');
    
    function page_spec_meta(){
    (this is line 6)	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
     if ($template_file == 'talenten.php')
        {
    		add_meta_box("career-meta", "Career", "career_meta", "page", "normal", "high");
            add_meta_box("business-meta", "Business", "business_meta", "page", "normal", "high");
            add_meta_box("inspired-meta", "inspired", "inspired_meta", "page", "normal", "high");
            add_meta_box("network-meta", "Network", "network_meta", "page", "normal", "high");
            add_meta_box("future-meta", "Future", "future_meta", "page", "normal", "high");
        }
    	if ($template_file == 'bedrijven.php')
        {
    		add_meta_box("unique-meta", "Unique", "unique_meta", "page", "normal", "high");
            add_meta_box("providing-meta", "Providing", "providing_meta", "page", "normal", "high");
            add_meta_box("inspired-meta", "inspired", "inspired_meta", "page", "normal", "high");
            add_meta_box("network-meta", "Network", "network_meta", "page", "normal", "high");
            add_meta_box("future-meta", "Future", "future_meta", "page", "normal", "high");
        }
    }
    
    ....rest of the page
    ?>

    I can’t really figure out what’s wrong. It can’t be whitespaces, checked all that.

Viewing 15 replies - 1 through 15 (of 19 total)
  • 99% of the time this error is caused by whitespace in functions.php.

    Try removing the closing ?> from both metaboxes.php and functions.php.

    Doesn’t do the trick. Someone else told me it could be that add_meta_box is outputting html is messing it up, could that be it?

    Moderator Andrew Nevins

    @anevins

    Is (this is line 6) in your actual code?

    Nope, just a note to show where the 6th line is (that’s where the error starts).

    Moderator Jan Dembowski

    @jdembowski

    Brute Squad and Volunteer Moderator

    It’s almost certainly your theme but that’s easy to confirm.

    Try switching to to the Twenty Eleven by using FTP or other file management and rename themes/yourconnector to themes/yourconnector-old. Then visit http://your-url-here/wp-admin/themes.php page and you should be switched to the Twenty Eleven theme.

    Doesn’t do the trick. Someone else told me it could be that add_meta_box is outputting html is messing it up, could that be it?

    Shouldn’t be, that would cause a different error I think. Can you use pastebin.com and post the link to that for that entire file? Line numbers work there and the forum here does not handle code that well.

    It could be your functions.php or it could also be your wp-config.php file too even though it’s not given you grief before.

    http://codex.wordpress.org/FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem.3F

    http://pastebin.com/52UZYqaY

    Not sure what switching themes is going to do, but I’ll go ahead and do that.

    And I already checked that link before, whitespaces are not the problem, I’m pretty sure of that. wp-config is clean as it came in the package, only thing I did was turn debug on.

    Moderator keesiemeijer

    @keesiemeijer

    Everything works fine except when trying to save anything

    Do you print or echo something out in your metabox code when saving a post?

    example from: http://codex.wordpress.org/Function_Reference/add_meta_box#Example

    /* Do something with the data entered */
    add_action( 'save_post', 'myplugin_save_postdata' );

    Can you show us the code where you save your metabox data?

    Can you show us the code where you save your metabox date?

    Check my previous comment, that’s the metaboxes.php file that has everything.

    Moderator Jan Dembowski

    @jdembowski

    Brute Squad and Volunteer Moderator

    Not sure what switching themes is going to do, but I’ll go ahead and do that.

    It’s just part of the check list and will help confirm where the problem may be.

    A succesful save with twentyeleven, so that’s my theme’s issue right?
    Weird thing is it this issue came out of nowhere.

    Moderator Jan Dembowski

    @jdembowski

    Brute Squad and Volunteer Moderator

    I just checked, this is a duplicate post you’ve created.

    http://wordpress.org/support/topic/unusual-issues-with-both-wordpress-and-my-theme-wp-admin-related?replies=2

    Don’t do that, it really makes it hard for us to support you. If it weren’t for the fact that you’ve 2 moderators helping you I’d normally close the newer topic down with a note.

    I’ll let it go this time. 😉

    A succesful save with twentyeleven, so that’s my theme’s issue right?

    It’s probably is a theme issue but still could be something else. Have you updated anything lately?

    Let’s see if it can be narrowed down some more. While the Twenty Eleven theme is active, deactivate all of your plugins and then switch back to that theme.

    Did the error come back after all of the plugins were deactivated?

    Sorry, but getting no answer and not being able to find anything else in on the internet being similar to this gets stressful. I’ll stick to the rules from now on 🙂

    Only active plugin was Contact Form 7, did as you said and still the same issue.
    Regarding updates, only things I did were replace wp-admin and wp-includes (only those folders, not the config files and such) and upload and remove tinymce.

    Moderator Jan Dembowski

    @jdembowski

    Brute Squad and Volunteer Moderator

    Theme issue or wp-config.php but what’s changed…?

    Which theme are you using? If you have backups (…you do have backups right…?) then save your current theme and see if uploading a fresh copy see if that can narrow it down even more.

    I’m using a custom theme made by me and 2 other front-end developers. Everything made from the ground up basically.

    Back-ups are made when the website is ready to go live so nope… none yet.

    I keep thinking it’s got to do with the metaboxes file, because I really didn’t make any other changes, certainly nothing to do with php. I did edit the admin-header.php file but then again I completely replaced wp-admin.

    If you really need to I could post a link to the development url of the site, not sure if that would help.

    Moderator keesiemeijer

    @keesiemeijer

    Warning: Cannot modify header information – headers already sent by (output started at /home/yc/domains/yc.keytoe.nl/public_html/wp-content/themes/yourconnector/inc/metaboxes.php:6) in /home/yc/domains/yc.keytoe.nl/public_html/wp-includes/pluggable.php on line 881

    Is that the only error?

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Resolved] Cannot modify header information error – functions.php’ is closed to new replies.
Skip to toolbar