WordPress fix

Before and after

Broken — before
<?php // searchform.php (Broken WordPress search input without <label>) ?>
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
  <input
    type="search"
    class="search-field"
    placeholder="Search articles..."
    value="<?php echo get_search_query(); ?>"
    name="s"
  />
  <button type="submit" class="search-submit">Search</button>
</form>
Fixed — after
<?php // searchform.php (Fixed with wp_unique_id() + accessible .screen-reader-text label) ?>
<?php $search_id = wp_unique_id( 'site-search-' ); ?>
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
  <label for="<?php echo esc_attr( $search_id ); ?>" class="screen-reader-text">
    <?php esc_html_e( 'Search articles', 'mytheme' ); ?>
  </label>
  <input
    id="<?php echo esc_attr( $search_id ); ?>"
    type="search"
    class="search-field"
    placeholder="<?php esc_attr_e( 'Search articles...', 'mytheme' ); ?>"
    value="<?php echo get_search_query(); ?>"
    name="s"
  />
  <button type="submit" class="search-submit">
    <?php esc_html_e( 'Search', 'mytheme' ); ?>
  </button>
</form>
Live preview

Fixed vs. broken example

Passes label
Accessibility tree: role="textbox", accessible name="Work email address" (programmatically bound via <label for="demo-work-email">)

Click directly on the "Work email address" label in the fixed preview: native browsers expand the hit target and immediately move focus into the input.

Automated test

Playwright + axe-core check

tests/a11y-label.spec.ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test("WordPress searchform and contact inputs pass axe-core label", async ({ page }) => {
  await page.goto("/contact/");
  const results = await new AxeBuilder({ page })
    .withRules(["label"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

An unlabeled search field in searchform.php triggers on every WordPress post, archive, and 404 page. Fixing searchform.php once clears that entire site-wide cluster in A11yDrift.

Screen readers

What NVDA and VoiceOver announce

Placeholder-only inputs lose their hint the moment a user starts typing, cannot be focused by clicking a visible label target, and leave screen-reader and cognitive-disability users guessing which data belongs in each field during checkout or signup.

NVDA (Windows)

Broken

"edit, has auto complete, blank" (no field purpose announced)


Fixed

"Work email address, edit, has auto complete, blank"

VoiceOver (macOS / iOS)

Broken

"edit text, Work email address" (inconsistent placeholder fallback that disappears once filled)


Fixed

"Work email address, edit text"

Common questions

How do I fix missing labels in Contact Form 7?
Wrap every CF7 field tag in an explicit HTML <label for='cf7-email'>Email</label> paired with id:cf7-email inside the shortcode (e.g., [email* your-email id:cf7-email autocomplete:email]).
Why use wp_unique_id() inside WordPress searchform.php?
Many themes render the search form in both the header and the footer or sidebar. wp_unique_id('site-search-') guarantees unique id/for bindings on every instance.
Do Gravity Forms and WPForms automatically generate valid labels?
They do by default, but hiding field labels via display:none or checking 'Hide Label' in older templates can strip the accessible name unless an accessible visually-hidden class is used.