Fix role attribute in WordPress Search Widget

Homepage > Home > Coding > Fix role attribute in WordPress Search Widget

Fri 03/12/2010

in Coding, PHP

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');


No Related Posts

Tags: ,

14 Responses to this post:

Leave a Reply ()

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

* required.