Fix label in WordPress
WordPress sites frequently fail the label rule in custom searchform.php overrides, legacy Contact Form 7 shortcodes that omit [label], and WooCommerce sidebar widgets. Using wp_unique_id() to generate unique for/id pairs ensures every search and contact input announces clearly without colliding across header and sidebar widgets.
Before and after
<?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><?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>Fixed vs. broken example
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.
Playwright + axe-core check
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.
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)
"edit, has auto complete, blank" (no field purpose announced)
"Work email address, edit, has auto complete, blank"
VoiceOver (macOS / iOS)
"edit text, Work email address" (inconsistent placeholder fallback that disappears once filled)
"Work email address, edit text"
Common questions
How do I fix missing labels in Contact Form 7?
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?
Do Gravity Forms and WPForms automatically generate valid labels?
Test a URL for label
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Managing WordPress client sites? Monitor 15 sites on one flat plan with white-label portals and branded executive PDFs—$1,140/yr ($95/mo billed annually, 24-month rate lock + onboarding) for Founding 10 agencies.