Doctype in WordPress – How to change DOCTYPE

by Peter

Most WordPress blogs seem to use either 1.0 Strict or 1.0 Transitional. This makes some sense, given that the WordPress engine unfortunately delivers output in XHTML rather than HTML format. Because of this, pure HTML doctypes, such as DOCTYPE 4.01 Transitional, are not good choices for bloggers using WordPress for the moment.

However, HTML 5 is also an alternative, as it’s syntax is compatible with WordPress: The Twenty Ten theme that was distributed with WordPress 3.0 used DOCTYPE HTML (HTML 5).

In WordPress, DOCTYPE is set by the theme. The developer may choose DOCTYPE on the basis of personal preference or what he or she is most used to working with. Many developers prefer DOCTYPE 1.0 Strict. Some do it because 1.0 Strict means the code meets very strict quality standards. Which, of course, is good news for people wanting to use the theme and probably works as a sales argument.

However, regardless of the choice of the theme developer, it is ultimately the coding style and preferences of the people using the themes in their blogs that determine which DOCTYPE is the right one for a particular blog. If the blog posts are written in a style that is more compatible with 1.0 Transitional, then the DOCTYPE should be transitional as well. If the blog uses plugins and features that are in HTML 5, then most likely the DOCTYPE for the blog should be HTML 5 as well. As the respected WordPress developer Alex King says:

The main reason we choose to use XHTML 1.0 Transitional for our WordPress themes is simple: we have no idea what someone might decide to do with it. :)

It doesn’t matter if the theme validates strictly if the content doesn’t – and with all of the great tools and widgets available for WordPress, it’s pretty easy to add something that breaks your strict validation.

This is something you should consider if you’re a theme developer. Don’t just think about the code you’ve written to build the theme, think about what people using your theme will be doing with it; and make the best choice you can.

The point here is not that Alex King prefers 1.0 Transitional, but rather his argument that it doesn’t matter if the theme validates if the content doesn’t – meaning that the most important thing is that the DOCTYPE is right for the blogger and the content of the blog. (See also Fix Your Site With the Right DOCTYPE! by Jeffrey Zeldman.)

The choice of DOCTYPE, therefore, is a choice you – as a blogger – should make. It is also a choice you can make, as it is fairly easy to change the DOCTYPE of your WordPress blog.


W3C has a complete list of recommended Doctype declarations, but here are the three most likely and most suited candidates for WordPress blogs:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

The first is 1.0 Strict, the second is 1.0 Transitional, and the third and much shorter one is HTML 5.

Which one to choose is up to you. I use 1.0 Transitional on this blog. Elsewhere I use 1.0 Strict. And I am about to move a couple of blogs over to HTML 5. What I run depends on the content and what I do in a blog or website. In this blog I have some stuff that has deprecated HTML tags, so 1.0 Transitional suits me best. On another blog I have some plugins that will not validate unless I move to HTML 5, so I will do that. The way I see it, the choice of DOCTYPE is a pragmatic choice, one of convenience, not a deep principled choice of coding philosophy. Other people may have a different take on that.

Some references if you want to learn more about DOCTYPES: HTML5 differences from HTML4 (W3C), Dive into HTML by Dave Pilgrim gives a nice overview of HTML5, see also Put XHTML 1.0 Strict and Transitional to work, HTML/XHTML Elements and Valid DTDs

Why not 1.0 Strict

From a purist point of view it can be argued in favor of other DOCTYPEs than 1.0 Strict. As most browsers actually parse XHTML documents as “text/html” and the state of XHTML is somewhat less than unproblematic on the net (see Beware of XHTML), there is little reason to prefer Strict 1.0 for parsing or rendering reasons. Also, if you want it to, HTML is no less “clean” than XHTML – you can code in lowercase, close all the tags and so on if you want.

From a more practical point of view, 1.0 Transitional or HTML 5 will in many cases be better choices than 1.0 Strict for bloggers:

  1. They both allow some tags that are not allowed in 1.0 Strict (deprecated elements and attributes), such as “target=_blank” (“target=”_blank” will not validate, but still works just fine in Strict – the browser makers are more pragmatic than W3C)
  2. The 1.0 Transitional and especially HTML 5 DOCTYPEs provide better platforms for use of embedded multimedia objects such as video and music in blogs and websites
  3. Some of the social media plugins in WordPress (Facebook-plugins especially) will work but not validate unless the DOCTYPE is HTML 5.
  4. If you have ads in your blogs, many types of ads will create huge numbers of validation errors in 1.0 Strict (Amazon ads and links will do that regardless of DOCTYPE – the W3C validator (and some other ones as well) has an hysterical fit when it sees an ampersand – & – that isn’t written as &amp;, but again the browsers render correctly in this case as well, so you can overlook the validator if you want to)
  5. Also, keep in mind that many ads use the “iframe”-tag. This tag is not permitted in 1.0 Strict or 1.1 XHTML. Neither is it permitted in HTML5. So if you have this type of ads, you may want to change the Doctype to 1.0 Transitional.
  6. I suspect many users of WordPress do not and will not adhere to the requirements of Strict 1.0 – e.g. do not close all tags properly, place inline styles in their posts and the like.

There are many other reasons for changing to another DOCTYPE, but these are the ones I view as the most important. But see also Why Transitional Doctypes are Better for WordPress Blogs

How change DOCTYPE in your WordPress blog?

You need to use either the built-in theme-editor in WordPress or preferably an editor on your local machine and a FTP-program. The file you want to modify is in the WordPress directory where your theme resides and is most often called “header.php” (e.g. “/wp-content/themes/(“name of your theme”)/header.php”). The first thing to do is to make a copy of this file as a backup.

In one of the themes I use the first line in header.php is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

In this case all that is needed is to copy and paste the exact code for the DOCTYPE I want to use from the listing above instead of this one (you want to copy and paste, as it is imperative that the letters are exactly the same), save it and replace the old “header.php”.

In the default WordPress 3.0 theme TwentyTen it looks like this:

&lt; ?php &amp;&gt;

This declares HTML 5, and here it is a matter of replacing the text after ?&gt; (which is part of the PHP) on the first line with the DOCTYPE we want, for instance like so:

&lt; ?php ""&gt; ?&gt;

and leave the second line as it was. Again save (and replace) header.php on the server, and all is well.

That’s it. Look in “header.php”, find the DOCTYPE declaration, carefully replace it with the one you want, save and replace it on the server, and there you go. If you can’t find the DOCTYPE declaration in the “header.php”, you may need to look in other php-files or get in touch with the developer of your theme. But most often you will find it there.

Related Posts:

{ 2 comments… read them below or add one }

Leave a Comment