While validating a Wordpress theme, I’veĀ noticed that the default search widget outputted a role HTML attribute in the form tag that wasn’t valid in the XHTML 1.0 specification:
<form role="search" method="get" id="searchform" action="">
[...]
</form>
As for the spec, role is an attribute introduced in XHTML draft for accessibility, but still not valid.
If you need valid documents, the fastest way to get rid of this attribute is to edit the get_search_form() function in general-template.php core file, but for better compatibility and safer future upgrades you can target the issue from your theme’s functions.php file by adding the following lines:
function valid_search_form ($form) {
return str_replace('role="search" ', '', $form);
}
add_filter('get_search_form', 'valid_search_form');
5 Responses to this post:
-
I’m working on a custom theme with support for widgets – and this Wordpress quirk was driving me mad! Thank you for sharing an elegant fix.
-
Thanks for this, sorted it out in my theme!
-
Thx a lot, worked like a charm on wp v3.0.1
-
Thx a lot, 0 error = sounds good !

I love you! Thank you for this you have made my life so much easier. I have to make a theme XHTML valid for someone and you have fixed the last problem.
Great Job!