WordPress and XHTML 1.0 Transitional

Many people ignore W3C markup validation. I am not one of them, so when I checked if my site was valid only to find that WordPress on a fresh install had an error I was rather annoyed.

The error found: there is no attribute “role”:

You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the “Strict” document type with a document that uses frames (e.g. you must use the “Transitional” document type to get the “target” attribute), or by using vendor proprietary extensions such as “marginheight” (this is usually fixed by using CSS to achieve the desired effect instead).

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

 

After doing some searching on Google it seems that this problem has been around in WordPress for awhile now. It also seems they are not interested in fixing it. However some people have stated that the easiest way to fix it is to implement your own searchform.php without the role attribute. This is easier said then done as most themes do not modify this file and have no reason to include it in a distribution.  So after doing a little poking around I was able to find what was included in the template file and change it to suite my sites needs

 

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
	<div>
		<label class="screen-reader-text" for="s">Search For:</label>
		<input type="text" name="s" id="s" value="Search..." />
		<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
	</div>
</form>

As a result I am now able to proudly display the W3C Valid Icon!

Leave a Reply

*



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">