1

I've been trying to fix the issue where wp_head loads in the body tag in wordpress, and I've discovered that when I look at the page source, an extra HTML block appears before the code from my header.php file.

Here's what I've tried:

  1. Setting wp_debug to true
  2. ensuring that charset is UTF-8
  3. removing all text before the beginning of !DOCTYPE
  4. check for missing closing tags

This is my header.php file enter image description here

Here is the output source: You can see that my code is being rendered correctly.. but why am I getting a HTML block at the start of the document??

You can see that my code is being rendered correctly.. but why am I getting a HTML block at the start of the document?? Any help would be amazing. Thanks so much

  • @Abhik the header.php is the content in the first screenshot. – go_cuc Jan 7 '18 at 9:13
  • Can't see any odd in your code. Try moving the wp_head() call to before closing <head> tag. – Abhik Jan 7 '18 at 9:14
  • That didn't work... but thanks for the suggestion @Abhik – go_cuc Jan 7 '18 at 9:23
  • 1
    There's most likely some static HTML somewhere in your template files. copy your themes files to your computer, and search for the <title>Document</title> as text among the files. You'll probably find where it's being added. – Jack Johansson Jan 7 '18 at 10:26
0

I am really not sure what's causing this. Can you try with a minimal content in header.php? Something like this and see if the problem occurs?

<!doctype html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>  

And, meta tags doesn't support class attributes like you have in line 11.

  • thanks for the advice, i removed the meta class from the head and relocated the wp_head() to the bottom and it started to work correctly. Thanks for your help – go_cuc Jan 8 '18 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.