How to change doctype declarations in Magento 1.x

If you ever experience following w3c (http://validator.w3.org/) html validating errors? Solution is checking your Magento 1.x template files and set valid document type specified by W3C.

W3C DOCTYPE validating errors

  1.  “DOCTYPE” declaration not allowed in instance
  2. no document type declaration; will parse without validation
  3. document type does not allow element “HTML” here

Here is correct W3C reference for valid doctype.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Title</title>
</head>
<body>
<!-- ... body of document ... -->
</body>
</html>

Steps

  1. Open your template files located in magento installation directory located at /app/design/frontend/YOUR-TEMPLATE-FOLDER/template/page
  2. Open following files in your favourite editor.
    1column.phtml
    2column-left.phtml
    2columns-right.phtml
    3columns.phtml
  3. Check the following code before starting <head> section. You shouldn’t place any php codes or any other script tags before starting <!DOCTYPE tags. In Magento there should be only DISCLAIMER notice top of the <!DOCTYPE.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>

Magento replace “xml:lang” and “lang=” section with php echo statements. It’s normal behaviour in Magento and you don’t need to change this.
Hope this article help you to avoid W3C validation errors for Magento stores.
Please check W3C valid DTD list at https://www.w3.org/QA/2002/04/valid-dtd-list.html