WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Cannot modify header information error - functions.php (20 posts)

  1. carloravelli
    Member
    Posted 1 year ago #

    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.

  2. Shane Gowland
    Member
    Posted 1 year ago #

    99% of the time this error is caused by whitespace in functions.php.

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

  3. carloravelli
    Member
    Posted 1 year ago #

    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?

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

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

  5. carloravelli
    Member
    Posted 1 year ago #

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

  6. 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

  7. carloravelli
    Member
    Posted 1 year ago #

    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.

  8. keesiemeijer
    moderator
    Posted 1 year ago #

    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?

  9. carloravelli
    Member
    Posted 1 year ago #

    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.

  10. 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.

  11. carloravelli
    Member
    Posted 1 year ago #

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

  12. 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?

  13. carloravelli
    Member
    Posted 1 year ago #

    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.

  14. 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.

  15. carloravelli
    Member
    Posted 1 year ago #

    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.

  16. keesiemeijer
    moderator
    Posted 1 year ago #

    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?

  17. carloravelli
    Member
    Posted 1 year ago #

    It differs per page. On the page where I save the metaboxes I only get that error, yes. On pages that don't have the meta boxes I get errors telling me wordpress can't find the meta boxes, but that's logic.

  18. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with this metaboxes.php: http://pastebin.com/gr7zVEkU

    Check if WP_DEBUG is set to true in your wp-config.php:
    http://codex.wordpress.org/Debugging_in_WordPress

    If so, set it to false.

  19. carloravelli
    Member
    Posted 1 year ago #

    Magic! Did it have to do with the admin_init?
    I've got to look through that a couple of times to see what I did wrong.

    Works perfectly, thanks a lot!

  20. keesiemeijer
    moderator
    Posted 1 year ago #

    Magic! Did it have to do with the admin_init

    Your code produced a lot of Notices when WP_DEBUG was set to true, so I changed it to not produce any notices. When using the 'save_post' action hook you cannot produce errors or notices (or print or echo something out). If you do, you get the headers already sent by ... in wp-includes/pluggable.php error. I changed the admin_init to load-post.php action hook so it only executes on already published posts.

    I'm glad you got it solved.

Topic Closed

This topic has been closed to new replies.

About this Topic