![](/img/trans.png)
[英]How to remove warning Cannot modify header information - headers already sent by
[英]Warning: Cannot modify header information - headers already sent by in wordpress
無法在關於我們、課程、聯系我們等頁面添加內容..同時顯示添加內容錯誤
警告:無法修改標題信息 - 標題已由 /home/phptraining/public_html/wp- 中的(輸出開始於 /home/phptraining/public_html/wp-content/themes/health-center-lite/functions.php:95)發送admin/post.php 在第 235 行
和
警告:無法修改標題信息 - 標題已由 /home/phptraining/public_html/wp- 中的(輸出開始於 /home/phptraining/public_html/wp-content/themes/health-center-lite/functions.php:95)發送包括/pluggable.php 在線 1196
函數.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' );
?>
這與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標記)。 這里沒有必要。
此錯誤不是特定於wordpress的。 這是PHP的標准錯誤。 發生此問題的原因是,您試圖在該頁面中生成輸出(如php echo或呈現某些html)后修改標頭。
我希望這可以幫助你。
我的 WordPress 也有同樣的錯誤。
我正在安裝 ElementsKIT 插件以在我的標題中進行修改,但是在啟用模塊時出現以下錯誤:
警告:無法修改標題信息 - 標題已由 /home/customer/www/ 中的(輸出開始於 /home/customer/www/staging6.seoalive.com/public_html/wp-admin/includes/template.php:2528)發送staging6.seoalive.com/public_html/wp-includes/pluggable.php 在線 1340
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.