Why is this </head> tag stray and where’s the other <body> element?

I’m trying to figure out errors #5 & #6 stated here: https://validator.w3.org/nu/?showsource=yes&doc=http%3A%2F%2Fwww.criminal-lawyers.com.au#l213c125

This is a heavily abbreviated excerpt from the HTML page (indented and with some annotations added):

Read More
<!DOCTYPE html>
<html lang="en-US" prefix="og: http://ogp.me/ns#">
 <head>
  <meta name="google-site-verification" content="hC6haEDgNzt-f1TAXuv9CrzeH2K5caXUbr-b1XSXcUo" />
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>Criminal Lawyers Melbourne - Doogue O'Brien George</title>

<!-- Omitted huge number of <meta>, <link>, <style> and <script> elements -->

  <style type="text/css" id="custom-background-css">
    body.custom-background { background-color: #dddddd; }
  </style>
  <span style="display:none">SCS URL: http://www.criminal-lawyers.com.au<br>Page Id: 5150<br></span>
  <link href="https://plus.google.com/100949400750888670994" rel="publisher"/>
  <script type="text/javascript"> /* Omitted */ </script>
 </head>  <!-- Line 211 -->

 <body onload="_googWcmGet('number', '03-9670-5111')" class="home page page-id-5150 page-template-default custom-background ">

<!-- Omitted -->

 </body>
</html>

Error messages from the Validator:

  1. Error: Stray end tag head.

    From line 211, column 1; to line 211, column 7

    </script>↩</head>↩↩<bod

  2. Error: Start tag body seen but an element of the same type was already open.

    From line 213, column 1; to line 213, column 125

    ↩</head>↩↩<body onload="_googWcmGet('number', '03-9670-5111')" class="home page page-id-5150 page-template-default custom-background ">↩ ↩ <d

But seriously, I don’t think the errors pointed out actually exist. How come the closing head tag is stray and that there’s another body element open? Whenever I check the source code, there’s only one closing head tag and there’s really only one open body tag. Where are these errors?

Will appreciate any feedback.

UPDATED July 3, 2015:

The span element as shown when checking the source code is not exactly like that at the back end. It is controlled by another set of codes:

<span style="display:none">
<?php
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
echo "SCS URL: ".$current_url."<br>";
$page_id = get_the_ID();
echo "Page Id: ".$page_id."<br>";
if($page_id == 5133){
?>
<script>
//document.title = "Lawyers Profile | Criminal Lawyers Melbourne - Doogue O'Brien George";
</script>
<?php
//echo "it's the page";
}else{
//echo "it's not the page";
}
?>
</span>

The above is what’s actually on the back end. I tried transferring this to the body and also tried simply deleting it. Both ways resulted to further errors.

Okay, I think it’s wrong to assume that the further errors were due to the fix. As mentioned by one of the commenters below, by fixing one error, you enable the validator to find other errors.

Related posts

2 comments

  1. In HTML, the HEAD and BODY (and HTML) elements are always present*. The tags that mark the start and end of the elements, however, are optional. The HTML parser will insert the open and closing tags as needed depending on what markup the document contains.

    When it encounters the <span>, which is not allowed inside the HEAD element, it implicitly closes the HEAD and opens the BODY element as if there was a </head> and a <body> tag present.

    Later, the parser comes across the </head> tag for a HEAD element that is already closed, and a <body> tag which attempts to open another BODY element.

    Just remove the SPAN, move it into the BODY element or work the contents into the TITLE or similar.


    *HTML4 frameset documents must have a FRAMESET element instead of a BODY.

  2. The issue is that you have a <span> element in <head> this is not valid.

    <span style="display:none">
    SCS URL: http://www.criminal-lawyers.com.au<br>Page Id: 5150<br></span>
    

    Get rid of this and your problem is resolved.

Comments are closed.