The MU forums have moved to WordPress.org

Error with custom header image API (11 posts)

  1. JMF
    Member
    Posted 17 years ago #

    I've just been experimenting with adding custom image headers à la here.

    I modified the Red Planet theme (very easy, a simple header image, with no overlaid text or anything), and everything went smoothly. I uploaded and cropped a new header image with no problem, and it appeared correctly on my test blog.

    When I tried to switch to a new theme, however, I got this error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/rchsteac/public_html/wp-content/themes/!-redplanet/functions.php:3) in /home/rchsteac/public_html/wp-includes/pluggable.php on line 334

    It's not fatal: Loading the main blog page shows the new theme, and returning to the admin presentation panel, everything looks like it's in one piece. Still, an ugly and frightening message to show to a user!

    Any idea what's causing that?

  2. drmike
    Member
    Posted 17 years ago #

    *sigh* You are going to put up the function.php file into a text file somewhere so we can see what you've done, right? All we can do right now is guess.

  3. JMF
    Member
    Posted 17 years ago #

    Sure, sorry. Didn't want to spamalot if it was a common issue. :) Here's the functions file (txt) to look at -- wasn't thinking to txt-ify it. :(

    Thanks.

  4. suleiman
    Member
    Posted 17 years ago #

    did this issue get resolved for you JMF?

  5. drmike
    Member
    Posted 17 years ago #

    First I saw of this response. Sorry. Any empty spaces after the end of that first line in the functions.php? That would be my guess.

  6. JMF
    Member
    Posted 17 years ago #

    Whew. I just got back to this today, and it does seem to be working as advertised. For the record (in case anybody else needs it) here's what worked:

    I started with a clean theme, Small Potato's Dream On this time.

    I edited the functions.php file to look like this: custom-header-2nd-try.txt

    It works beautifully. I'm guessing I had some kind of cruft running around in my first try, as per drmike's suggestion.

    Anyway, hope that's helpful to someone!

  7. drmike
    Member
    Posted 17 years ago #

    Don't you hate errors like that? Can't point at somethign specific and you gotta search through everything.

  8. JMF
    Member
    Posted 17 years ago #

    Those seem to be the only kind I get. ;) Either that, or I figure them out MOMENTS AFTER I ask a question about them! :P

  9. JMF
    Member
    Posted 17 years ago #

    Whoops. Then there's the "spoke too soon" mistake. I just discovered that (with a theme I've modified for custom headers) I can't activate or deactivate plugins!

    The error I'm getting is:
    Warning: Cannot modify header information - headers already sent by (output started at /home/rchsteac/public_html/wp-content/themes/blackish/functions.php:25) in /home/rchsteac/public_html/wp-includes/pluggable.php on line 338

    Line 25 in functions is where the declarations for the custom header code begin:

    <?php
    define('HEADER_TEXTCOLOR','#000000);
    etc.

    I'm guessing this is all interfering with the way the admin menus are displayed? (Going to the Plugins menu in another web browser confirms that the plugins I activated and deactivated WERE, in fact, turned on and off, so this is a display issue and not a functionality issue...)

    I don't really know what that error means, exactly, so I'm not sure what to mess with to try to start debugging.

    Can anyone offer any suggestions?

    [ Man, and I thought it was clear sailing from here, too. :( ]

  10. JMF
    Member
    Posted 17 years ago #

    Derp. I think I may have figured this one out, too. Sorry. Would someone be so kind as to possibly confirm if this makes sense?

    The particular theme I had enabled already had a functions.php that looked like this:

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Sidebar',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '',
    'before_title' => '<h2 class="sidebartitle">',
    'after_title' => '</h2>',
    ));
    
    // Search
    function widget_zone_out_search() {
    ?>
    
    <li class="list-search">
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    <?php
    }
    if ( function_exists('register_sidebar_widget') )
    register_sidebar_widget(__('Search'), 'widget_zone_out_search');
    ?>
    

    When I added the custom header code, I tacked it right on the end, so the last part of the file looked like this:

    [beginning file stuff]
    ...
    <li class="list-search">
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    <?php
    }
    if ( function_exists('register_sidebar_widget') )
    register_sidebar_widget(__('Search'), 'widget_zone_out_search');
    ?>
    
    <?php
    define('HEADER_TEXTCOLOR', '#000000');
    define('HEADER_IMAGE', '%s/images/image_header.jpg'); // %s is theme dir uri
    define('HEADER_IMAGE_WIDTH', 700);
    define('HEADER_IMAGE_HEIGHT', 225);
    
    function header_style() {
    [rest of custom header code]
    ...
    ?>
    

    To stop the "headers already sent" error, I got rid of the

    
    ?> <?php
    
    between the pre-existing functions.php code and the custom header code:

    
    ...
    if ( function_exists('register_sidebar_widget') )
    register_sidebar_widget(__('Search'), 'widget_zone_out_search');
    
    define('HEADER_TEXTCOLOR', '#000000');
    define('HEADER_IMAGE', '%s/images/image_header.jpg'); // %s is theme dir uri
    ...

    That seems to have done the trick. Can somebody explain WHY? It seemed like a logical thing to try, but I'd kind of like to know why it works...

    Thanks!

  11. andrea_r
    Moderator
    Posted 17 years ago #

    Because the ?> end the php, then there was a space - which causes the "headers not sent out error - and then the <? php opens it up again.

About this Topic