Unwanted blank lines before <html> tag

I’ve a strange problem with an Autofocus theme.

In my templates file, header.php, I’ve a code like this (and is correct)

Read More
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

When I look at the source code of the generated HTML, I found something like this

[blank]
[blank]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

The extra blank lines are breaking my RSS feeds…

Other info:

  • No filters on the content except wpautop
  • functions.php doesn’t do anything on the content
  • Plugins All In One Seo, WP Stats, Smiley Remover, SEO Friendly images

Any clues?

Related posts

Leave a Reply

2 comments

  1. the_content doesn’t affect the DOCTYPE and <html> tags, only the post/page content.

    One of your plugins, or something else in the theme is either throwing an error, or is printing something earlier than it should.

    Have you tried:

    • Disabling each plugin one by one and see when it is fixed.
    • Editing wp-config.php and adding define( 'WP_DEBUG', true ); to look for errors
  2. I believe the problem is that there are not any <?php opening tags in your header.php so the space is probably coming from your templates that call <?php get_header(); ?>

    Try adding a commented out header like so:

    <?php
    /**
     * The Header for our theme.
     *
     * Displays all of the <head> section 
     *
     */
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    

    It’s also possible that you have windows line endings which sometimes get parsed as a dbl line ending adding an extra space to each line.