警告:无法修改标题信息 - 标题已在 wordpress 中发送 [英] Warning: Cannot modify header information - headers already sent by in wordpress

查看:36
本文介绍了警告:无法修改标题信息 - 标题已在 wordpress 中发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在关于我们、课程、联系我们等页面中添加内容..同时显示添加内容错误

<块引用>

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

<块引用>

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

functions.php

 <?php/**包括所需资源**/定义('WEBRITI_TEMPLATE_DIR_URI',get_template_directory_uri());定义('WEBRITI_TEMPLATE_DIR',get_template_directory());定义('WEBRITI_THEME_FUNCTIONS_PATH',WEBRITI_TEMPLATE_DIR.'/functions');定义('WEBRITI_THEME_OPTIONS_PATH',WEBRITI_TEMPLATE_DIR_URI.'/functions/theme_options');要求(WEBRITI_THEME_FUNCTIONS_PATH.'/menu/default_menu_walker.php');//对于默认菜单要求(WEBRITI_THEME_FUNCTIONS_PATH.'/menu/webriti_nav_walker.php');//自定义菜单要求(WEBRITI_THEME_FUNCTIONS_PATH.'/commentbox/comment-function.php');//评论要求(WEBRITI_THEME_FUNCTIONS_PATH.'/widget/custom-sidebar.php');//用于小部件注册//内容宽度如果(!isset($content_width))$content_width = 900;//wp 标题标签从这里开始函数 hc_head( $title, $sep ){ 全局 $paged, $page;如果 ( is_feed() )返回 $title;//添加站点名称.$title .= get_bloginfo( 'name' );//添加主页/首页的站点描述.$site_description = get_bloginfo('description');if ( $site_description && ( is_home() || is_front_page() ) )$title = "$title $sep $site_description";//如有必要,添加页码.if ( $paged >= 2 || $page >= 2 )$title = "$title $sep" .sprintf( _e( 'Page', 'helth' ), max( $paged, $page ) );返回 $title;}add_filter('wp_title', 'hc_head', 10,2);add_action('after_setup_theme', 'hc_setup');函数 hc_setup(){//加载文本域以备翻译load_theme_textdomain('health', WEBRITI_THEME_FUNCTIONS_PATH .'/lang');add_theme_support('后缩略图');//支持特色图片//此主题在一个位置使用 wp_nav_menu().register_nav_menu('primary', __('Primary Menu', 'health'));//主题支持$args = array('default-color' => '000000',);add_theme_support( '自定义背景', $args );add_theme_support('自动馈送链接');require_once('theme_setup_data.php');需要(WEBRITI_THEME_FUNCTIONS_PATH.'/theme_options/option_pannel.php');//自定义菜单//为索引页面设置管理面板默认数据$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');//获取现有的选项数据如果($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);}别的{ add_option('hc_lite_options',$health_center_lite_theme);}}/********健康中心js和cs *********/函数 hc_scripts(){//主题 CSSwp_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" );}//阅读更多标签以在博客页面中格式化函数 hc_content_more($more){ 全球 $post;return ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"hc_blog_btn\">阅读更多<i class='fa fa-long-arrow-右'></i></a>";}add_filter('the_content_more_link', 'hc_content_more');?><?php/*** 注册小部件区域.**/函数 wpgyan_widgets_init() {register_sidebar( 数组('名称' =>'标题侧边栏','id' =>'header_sidebar','before_widget' =>'

','after_widget' =>'</div>','before_title' =>'<h2 class="rounded">','after_title' =>'</h2>',) );}add_action('widgets_init', 'wpgyan_widgets_init');?>

解决方案

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

<代码>?><?php

关闭和打开 PHP 标记之间的空行是导致错误的原因.相反,你应该去掉这两个标签,这样你的代码就会变成:

add_filter( 'the_content_more_link', 'hc_content_more' );/*** 注册小部件区域.**/函数 wpgyan_widgets_init() {

同时删除 functions.php 文件的最后一行(关闭 ?> PHP 标记).这里没有必要.

unable to add contents in pages like about us ,courses,contact us..while adding the content error is displaying

Warning: Cannot modify header information - headers already sent by (output started at /home/phptraining/public_html/wp-content/themes/health-center-lite/functions.php:95) in /home/phptraining/public_html/wp-admin/post.php on line 235

and

Warning: Cannot modify header information - headers already sent by (output started at /home/phptraining/public_html/wp-content/themes/health-center-lite/functions.php:95) in /home/phptraining/public_html/wp-includes/pluggable.php on line 1196

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' );
    ?>

解决方案

This has nothing to do with functions.php sending headers. Rather, it has to do with output having started (in the functions file) before headers are sent (by other WordPress scripts). What you'll see, if you look on line 95, is the following:

?>

<?php

That blank line between the closing and opening PHP tags is the cause of the error. Instead, you should get rid of both of those tags, so that your code becomes:

add_filter( 'the_content_more_link', 'hc_content_more' );

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

While you're at it, also delete the last line of your functions.php file (the closing ?> PHP tag). It's unnecessary here.

这篇关于警告:无法修改标题信息 - 标题已在 wordpress 中发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆