1

I'm getting this error (I activated wp-debug) when I try to activate a theme or when I try to save a post:

Warning: Cannot modify header information - headers already sent by (output started at /mnt/webv/b3/13/56920413/htdocs/WordPress_02/wp-content/themes/BackpackFamily/functions.php:58) in /mnt/webv/b3/13/56920413/htdocs/WordPress_02/wp-admin/post.php on line 197

Warning: Cannot modify header information - headers already sent by (output started at /mnt/webv/b3/13/56920413/htdocs/WordPress_02/wp-content/themes/BackpackFamily/functions.php:58) in /mnt/webv/b3/13/56920413/htdocs/WordPress_02/wp-includes/pluggable.php on line 1171

That's the code of my functions.php, what did I do wrong?

<?php

// Navigation

    if ( function_exists('register_nav_menus') ) {
        register_nav_menus(array(
            'main-navi' => __( 'Hauptnavigation' )
        ));
    }

// Thumbnails

    if ( function_exists( 'add_theme_support' ) )
        add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 200, 200, true );


// Read more Link

   function new_excerpt_more($more) {
       global $post;
       return ' … </br><a href="'. get_permalink($post->ID) . '">' . 'Mehr lesen &raquo;' . '</a>';
   }
   add_filter('excerpt_more', 'new_excerpt_more');
   


// Sidebar

    function sl_sidebar() {
        $args = array(
            'id'            => 'default_sidebar', 
            'name'          => __( 'Sidebar Header', 'text_domain' ),
            'description'   => __( 'Sidebar Header', 'text_domain' ),
            'before_title'  => '<h3><a href="#">',
            'after_title'   => '</a></h3>',
            'before_widget' => '',
            'after_widget'  => '',
        );
        register_sidebar( $args );
    }
    
    add_action( 'widgets_init', 'sl_sidebar' );

// Search Button

    add_filter('get_search_form', 'new_search_button');
    function new_search_button($text) {
        $text = str_replace('value="Suche"', 'value="Suchen"', $text);
        return $text;
    }
?>

Thanks for help!

Community
  • 1
  • 1
Benedikt W
  • 195
  • 4
  • 13
  • Which line in your code above is line 58? (The **notice** - not an error - says the issue is on line 58) – random_user_name May 14 '16 at 16:07
  • Well, actually (in Dreamweaver) it has just 52 lines, because I edited it. Before that, it was the last line – Benedikt W May 14 '16 at 16:13
  • The error is being reported in `post.php` and `pluggable.php` so why are you showing us `functions.php` – RiggsFolly May 14 '16 at 16:13
  • 1
    it isn't, if you look carefully you would have seen that they are wordpress files, in my template folder there aren't these files – Benedikt W May 14 '16 at 16:14
  • @RiggsFolly - the stray output starts in the `functions.php` file, not in the core WP files. Those notices are a consequence of the original issue. – random_user_name May 14 '16 at 16:15

3 Answers3

0

Per your comment, the notice is being thrown on the last line of your functions.php file.

Which causes me to believe that you likely have stray line-feeds and /or spaces in your file somewhere outside (before, after, or between) your php tags (<?php and ?>)

Remove the closing php tag at the end ?> - it's the WordPress recommended code style now to omit the closing php tag.

Also, be sure there's no stray line feeds before the opening <?php tag.

Side-comment:
This is a NOTICE, not really an error. If you had debug turned off, it would be a non-issue because notices would be silenced.
BUT...
Kudos to you for testing your code with WP_DEBUG set to true. This is the only way to be sure your code runs without notices!

random_user_name
  • 25,694
  • 7
  • 76
  • 115
  • Before that I had 58 lines but I removed the space between and now it's 52. But after that I reuploaded it, it's strange – Benedikt W May 14 '16 at 16:16
  • Well, I did this because I'm getting a white screen when I try to save a post when my theme is activated, I think that's because of that error. I tried to delete the ?> but still got the error. Do you have any other ideas – Benedikt W May 14 '16 at 16:19
  • You still got the white screen when saving a post? My only idea would be to try the twentysixteen theme and see if that issue is related to your theme. If it works right with twentysixteen, but not with your theme, then your theme has a problem. If it does NOT work right with twentysixteen, then either a plugin is causing the problem, or the WP core files are incomplete / corrupt – random_user_name May 14 '16 at 16:41
  • It works now, I had to transfer it with filezilla not with the build-in ftp – Benedikt W May 14 '16 at 16:57
0

I recommend you read the link provided too, so you get an understanding of this error in general. It might also fix your problem too.

Fix header error: https://stackoverflow.com/a/8028987/4205975

Community
  • 1
  • 1
freshfish
  • 16
  • 2
0

I think there are some space characters at last line of file functions.php you should to remove last ?> on that file.

tuongpg.jz
  • 104
  • 5