警告:无法修改标头信息 - 已在wordpress中发送的标头

时间:2015-05-16 11:29:03

标签: php wordpress

无法在关于我们,课程,联系我们的页面中添加内容......而添加内容错误正在显示

  

警告:无法修改标头信息 - 已在/ home / phptraining / public_html中发送的标头(输出从/home/phptraining/public_html/wp-content/themes/health-center-lite/functions.php:95开始)第235行/wp-admin/post.php

  

警告:无法修改标头信息 - 已在/ home / phptraining / public_html中发送的标头(输出从/home/phptraining/public_html/wp-content/themes/health-center-lite/functions.php:95开始)第1196行/wp-includes/pluggable.php

的functions.php

    <?php   /**Includes reqired resources here**/
        define('WEBRITI_TEMPLATE_DIR_URI',get_template_directory_uri());    
        define('WEBRITI_TEMPLATE_DIR',get_template_directory());
        define('WEBRITI_THEME_FUNCTIONS_PATH',WEBRITI_TEMPLATE_DIR.'/functions');   
        define('WEBRITI_THEME_OPTIONS_PATH',WEBRITI_TEMPLATE_DIR_URI.'/functions/theme_options');

        require( WEBRITI_THEME_FUNCTIONS_PATH . '/menu/default_menu_walker.php' ); // for Default Menus
        require( WEBRITI_THEME_FUNCTIONS_PATH . '/menu/webriti_nav_walker.php' ); // for Custom Menus   

        require( WEBRITI_THEME_FUNCTIONS_PATH . '/commentbox/comment-function.php' ); //for comments
        require( WEBRITI_THEME_FUNCTIONS_PATH . '/widget/custom-sidebar.php' ); //for widget register


        //content width
        if ( ! isset( $content_width ) ) $content_width = 900;      
        //wp title tag starts here
        function hc_head( $title, $sep )
        {   global $paged, $page;       
            if ( is_feed() )
                return $title;
            // Add the site name.
            $title .= get_bloginfo( 'name' );
            // Add the site description for the home/front page.
            $site_description = get_bloginfo( 'description' );
            if ( $site_description && ( is_home() || is_front_page() ) )
                $title = "$title $sep $site_description";
            // Add a page number if necessary.
            if ( $paged >= 2 || $page >= 2 )
                $title = "$title $sep " . sprintf( _e( 'Page', 'helth' ), max( $paged, $page ) );
            return $title;
        }   
        add_filter( 'wp_title', 'hc_head', 10,2 );

        add_action( 'after_setup_theme', 'hc_setup' );  
        function hc_setup()
        {   // Load text domain for translation-ready
            load_theme_textdomain( 'health', WEBRITI_THEME_FUNCTIONS_PATH . '/lang' );      

            add_theme_support( 'post-thumbnails' ); //supports featured image
            // This theme uses wp_nav_menu() in one location.
            register_nav_menu( 'primary', __( 'Primary Menu', 'health' ) );
            // theme support    
            $args = array('default-color' => '000000',);
            add_theme_support( 'custom-background', $args  ); 
            add_theme_support( 'automatic-feed-links'); 

            require_once('theme_setup_data.php');
            require( WEBRITI_THEME_FUNCTIONS_PATH . '/theme_options/option_pannel.php' ); // for Custom Menus       
            // setup admin pannel defual data for index page        
            $health_center_lite_theme=theme_data_setup();

            function hc_custom_excerpt_length( $length ) {  return 50; }
            add_filter( 'excerpt_length', 'hc_custom_excerpt_length', 999 );

            function hc_new_excerpt_more( $more ) { return '';}
            add_filter('excerpt_more', 'hc_new_excerpt_more');

            $current_theme_options = get_option('hc_lite_options'); // get existing option data         
            if($current_theme_options)
            {   $hc_lite_theme_options = array_merge($health_center_lite_theme, $current_theme_options);
                update_option('hc_lite_options',$hc_lite_theme_options);            
            }
            else
            {   add_option('hc_lite_options',$health_center_lite_theme);    }


        }
        /******** health center js and cs *********/
        function hc_scripts()
        {   // Theme Css 
            wp_enqueue_style('health-responsive', WEBRITI_TEMPLATE_DIR_URI . '/css/media-responsive.css');

            wp_enqueue_style('health-font', WEBRITI_TEMPLATE_DIR_URI . '/css/font/font.css');   

            wp_enqueue_style('health-bootstrap', WEBRITI_TEMPLATE_DIR_URI . '/css/bootstrap.css');  

            wp_enqueue_style('health-font-awesome', WEBRITI_TEMPLATE_DIR_URI . '/css/font-awesome-4.0.3/css/font-awesome.min.css'); 

            wp_enqueue_script('health-menu', WEBRITI_TEMPLATE_DIR_URI .'/js/menu/menu.js',array('jquery'));

            wp_enqueue_script('health-bootstrap_min', WEBRITI_TEMPLATE_DIR_URI .'/js/bootstrap.min.js');    
        }

        add_action('wp_enqueue_scripts', 'hc_scripts');
        if ( is_singular() ){ wp_enqueue_script( "comment-reply" ); }

        // Read more tag to formatting in blog page 
        function hc_content_more($more)
        {  global $post;
           return ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"hc_blog_btn\">Read More<i class='fa fa-long-arrow-right'></i></a>";
        }   
        add_filter( 'the_content_more_link', 'hc_content_more' );
       ?>

       <?php
    /**
     * Register Widget Area.
     *
     */
    function wpgyan_widgets_init() {

        register_sidebar( array(
            'name' => 'Header Sidebar',
            'id' => 'header_sidebar',
            'before_widget' => '<div>',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="rounded">',
            'after_title' => '</h2>',
        ) );
    }
    add_action( 'widgets_init', 'wpgyan_widgets_init' );
    ?>

2 个答案:

答案 0 :(得分:1)

这与 functions.php 发送标头无关。相反,它与在发送标题之前(在其他WordPress脚本中)已经启动的输出(在函数文件中)有关。如果查看line 95,您会看到以下内容:

?>

<?php

关闭和打开PHP标记之间的空白行是导致错误的原因。相反,您应该删除这两个标记,以便您的代码变为:

add_filter( 'the_content_more_link', 'hc_content_more' );

/**
 * Register Widget Area.
 *
 */
function wpgyan_widgets_init() {

在您使用它的同时,还要删除 functions.php 文件的最后一行(结束?> PHP标记)。这里没必要。

答案 1 :(得分:0)

此错误并非特定于wordpress。这是PHP的标准错误。出现此问题是因为您尝试在该页面中生成输出后修改标头,如php echo或呈现某些html。

我希望这会对你有所帮助。