Support » Fixing WordPress » ERROR: "Headers already sent"…

  • I already did everything the Codex says about this specific error (php white space).

    If I add ob_start() I don’t get the error anymore, but when I click on the logout link generated by wp_logout_url($redirect_url) it can’t log me out. I assume because it’s doing the redirect to the $redirect_url before it actually logs me out.

    Warning: Cannot modify header information - headers already sent by (output started at /.../wp-content/themes/themename/header.php:2) in /.../wp-includes/pluggable.php on line 896

    Let me know, I’ve tried a few other random things but I can’t recall all of them right now. Thanks!

Viewing 15 replies - 1 through 15 (of 15 total)
  • What happens if you switch to the 2014 default theme?

    I can log in/out fine through WordPress’ default login page.

    I have this error coming up on a few random pages only though, most pages load and work fine most of the time and don’t give that error when ob_start is disbaled. If I enable ob_start all works, except I can’t log out.

    And this is when using the default 2014 theme?

    No, this is a custom theme I’m making, sorry I didn’t specify that.

    The first sentence: “I can log in/out fine through WordPress’ default login page.” is with 2014 theme.

    The rest is with my custom theme.

    What happens if you switch to the 2014 default theme?

    Everything works fine with the default 2014 theme.

    My custom theme has custom templates for pretty much all the pages so the default 2014 theme only displays menu items and page titles.

    If the default theme works OK, then it implies that the problem lies in your custom theme. Why are you trying to use ob_start?

    I’ve know from the beginning the problem lies in my custom theme, that is not my concern.

    If I enable ob_start (which I really want to stay away from) I don’t get the error mentioned above:

    Warning: Cannot modify header information - headers already sent by (output started at /.../wp-content/themes/themename/header.php:2) in /.../wp-includes/pluggable.php on line 896

    I checked both the header.php and pluggable.php files for any white space at the top or bottom, but they’re clean.

    Did you try following the instructions in Solving “headers already sent” warnings for your theme’s header.php template file?

    Yes, I mentioned I did that too in my first post. Except, how do I make the very first character “<?php” and the very last “?>” ???

    It also mentions to use JavaScript redirect but the error sometimes appears when no redirects are done. And I can’t use JavaScript redirect for the log out process.

    Here’s my header.php:

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    	<meta charset="<?php bloginfo('charset'); ?>">
    	<meta name="viewport" content="width=device-width, user-scalable=no, minimal-ui">
    	<meta name="mobile-web-app-capable" content="yes">
    	<meta name="apple-mobile-web-app-capable" content="yes">
    	<meta name="apple-mobile-web-app-status-bar-style" content="black">
        <!-- iOS loading screens -->
    	<link rel="apple-touch-startup-image" media="(device-width: 320px)" href="<?php echo get_stylesheet_directory_uri(); ?>/img/splash-screen-320x460.jpg">
    	<link rel="apple-touch-startup-image" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" href="<?php echo get_stylesheet_directory_uri(); ?>/img/splash-screen-640x920.jpg">
    	<link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="<?php echo get_stylesheet_directory_uri(); ?>/img/splash-screen-640x1096.jpg">
    	<!-- Android touch icon -->
    	<link rel="shortcut icon" sizes="196x196" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.png">
        <!-- iOS touch icons -->
    	<link rel="apple-touch-icon" href="<?php echo get_stylesheet_directory_uri(); ?>/img/touch-icon-iphone.png">
    	<link rel="apple-touch-icon" sizes="76x76" href="<?php echo get_stylesheet_directory_uri(); ?>/img/touch-icon-ipad.png">
    	<link rel="apple-touch-icon" sizes="120x120" href="<?php echo get_stylesheet_directory_uri(); ?>/img/touch-icon-iphone-retina.png">
    	<link rel="apple-touch-icon" sizes="152x152" href="<?php echo get_stylesheet_directory_uri(); ?>/img/touch-icon-ipad-retina.png">
    	<title><?php wp_title( '|', true, 'right' ); ?> <?php bloginfo('name'); ?></title>
        <link rel="profile" href="" />
    	<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
        <?php if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); ?>
    	<!--[if gte IE 9]>
    	<style type="text/css">
    		.gradient {
    			filter: none;
    	<?php wp_head(); ?>
    <body <?php body_class(); ?>>
    <?php if ( is_user_logged_in() ) {
    $player = ug2p_user_info();
    $player_qr_data = '{"player": {"username":"' . $player->name . '","playerId":"' . $player->playerId . '"}}';
    <!-- QR Overlay -->
    <div class="overlay-item">
    	<div class="close-bar row cf">
    	<span class="title col span_5">My QR Code</span><span class="close-x no-highlight col span_1">X</span>
    	<img class="qr-overlay" src="<?php echo urlencode($player_qr_data); ?>&size=1500x1500" />
    	<p>To sign in to a UGot2Play kiosk, simply hold this QR code in front of the kiosk camera when prompted.</p>
    <?php if (is_page('my-profile')) { // Avatar selection pop-up ?>
    <!-- Avatar Selection -->
    <div id="avatar-selection">
    	<div class="close-bar row cf">
    	<span class="title col span_5">Select a Picture</span><span class="close-x no-highlight col span_1">X</span>
    	<div class="images cf"><?php ug2p_avatar_images(); ?></div>
    	<div class="confirmation row cf">
    		<button class="button green-btn gradient span_3">Okay</button>
    <?php }} ?>
    <header id="masthead" class="gradient row cf" role="banner">
    	<i class="nav-toggle fa fa-bars fa-lg no-highlight col span_1"></i>
    	<?php if (is_front_page()) { // Display logo in header?>
    	<a href="javascript:location.reload(true);"><img class="logo" src="<?php echo get_stylesheet_directory_uri(); ?>/img/website-logo.png" alt="uGot2Play" title="uGot2Play Logo" /></a>
    	<?php } else { // Display page/post title ?>
    	<h1 class="page-title col span_5"><a class="no-highlight" href="javascript:location.reload(true);"><?php echo get_the_title(); ?></a></h1>
    	<?php } ?>
    <?php $args = array('theme_location'  => 'header-menu', 'container' => 'nav', 'container_id' => 'header-menu'); wp_nav_menu($args); // Output header menu?>
    <main role="main">

    Download the file mentioned in the error message via FTP or the file manager provided in your host’s control panel.
    Open that file in a plain text editor (NOT MS Word or similar. Notepad or BBEdit are fine).
    Check that the very first characters are <?php
    Check that the very last characters are ?>

    To be sure about the end of the file, do this:

    Place the cursor between the ? and >
    Now press the DELETE key on your computer
    Note to MAC users: The “DELETE” key on a PC deletes characters to the right of the cursor. That is the key noted here.
    Keep that key pressed
    For at least 15 seconds
    Now type > and
    save without pressing any other key at all.
    If you press another key, you will bring the problem back.

    I did all that and I’m only getting the error on the sign in page by the way now, the other pages load fine.

    Try re-uploading all files & folders – except the root wp-config.php & .htaccess files and the wp-content folder – from a fresh download of WordPress 3.8.3. Make sure that you delete the old copies of files & folder before uploading the new ones.

    Why are you using an old copy of WordPress? Were you aware that your site is currently running a very real risk of being hacked? You need to upgrade WordPress asap.

    I plan to update before the week ends, this is a site I’m working on at my job so I can’t just update it immediately. I am first required (by my superiors) to backup everything first and they have me working on this issue as a first priority. I am well aware of the risks of running an older version, yet we are only one version behind and 3.9 was released not too long ago.

    I will do what you asked and get back to you, thanks.

    By the way this is a WordPress Multisite setup if that helps with anything. I am working on the custom theme for one of the “child” sites.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘ERROR: "Headers already sent"…’ is closed to new replies.