Skip to content

Commit ddb1363

Browse files
General: Use the semantic <search> element in core search markup.
Wrap the form output of `get_search_form()` (html5 format) and the `core/search` block in the HTML `<search>` landmark element, and drop the now-redundant `role="search"` attribute on the inner `<form>`. The `<search>` element is in Baseline and has an implicit ARIA landmark role of `search`, providing the same semantics as the existing `role="search"` attribute via native markup. The XHTML fallback in `get_search_form()` is left unchanged because XHTML 1.x does not include the `<search>` element. For `get_search_form()`, the optional `aria_label` argument is now applied to the `<search>` landmark element instead of the `<form>`, since the landmark is what assistive technology exposes. Props to all who will help review and refine this change.
1 parent ac5e1ac commit ddb1363

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/wp-includes/blocks/search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function render_block_core_search( $attributes ) {
189189
}
190190

191191
return sprintf(
192-
'<form role="search" method="get" action="%1s" %2s %3s>%4s</form>',
192+
'<search><form method="get" action="%1s" %2s %3s>%4s</form></search>',
193193
esc_url( home_url( '/' ) ),
194194
$wrapper_attributes,
195195
$form_directives,

src/wp-includes/general-template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function get_search_form( $args = array() ) {
322322
}
323323

324324
if ( 'html5' === $format ) {
325-
$form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
325+
$form = '<search ' . $aria_label . '><form method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
326326
<label>
327327
<span class="screen-reader-text">' .
328328
/* translators: Hidden accessibility text. */
@@ -331,7 +331,7 @@ function get_search_form( $args = array() ) {
331331
<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
332332
</label>
333333
<input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
334-
</form>';
334+
</form></search>';
335335
} else {
336336
$form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
337337
<div>

0 commit comments

Comments
 (0)