简体   繁体   中英

Getting wordpress error: Cannot modify header information

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!

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!

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

我认为在文件functions.php的最后一行有一些空格字符你应该删除该文件的最后一个?>。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM