Fix aria-valid-attr-value in WordPress
WordPress themes and slider/accordion plugins routinely ship broken aria-controls IDs when a sidebar or mobile drawer is disabled in Customizer settings, or output aria-expanded='1' when PHP casts a boolean ((string) true evaluates to '1' instead of 'true'). Always convert PHP booleans explicitly with $is_open ? 'true' : 'false'.
Before and after
<?php // template-parts/accordion.php (Broken: PHP true casts to "1" and false to "") ?>
<?php $is_open = ! empty( $args['open'] ); ?>
<button
type="button"
aria-expanded="<?php echo esc_attr( $is_open ); ?>"
aria-controls="panel-missing"
>
<?php echo esc_html( $args['title'] ); ?>
</button><?php // template-parts/accordion.php (Fixed: strict "true"/"false" + wp_unique_id()) ?>
<?php
$is_open = ! empty( $args['open'] );
$panel_id = wp_unique_id( 'accordion-panel-' );
?>
<button
type="button"
aria-expanded="<?php echo $is_open ? 'true' : 'false'; ?>"
aria-controls="<?php echo esc_attr( $panel_id ); ?>"
>
<?php echo esc_html( $args['title'] ); ?>
</button>
<div id="<?php echo esc_attr( $panel_id ); ?>"<?php echo $is_open ? '' : ' hidden'; ?>>
<?php echo wp_kses_post( $args['content'] ); ?>
</div>Fixed vs. broken example
Never interpolate unvalidated booleans, undefined IDs, or custom strings like 'open'/'closed' into ARIA attributes; only render aria-controls when the controlled ID exists in the DOM.
Playwright + axe-core check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("WordPress accordions and theme navigation pass aria-valid-attr-value", async ({ page }) => {
await page.goto("/faq/");
const results = await new AxeBuilder({ page })
.withRules(["aria-valid-attr-value"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
A PHP boolean echoed directly into aria-expanded='<?php echo $open; ?>' inside header.php or a shared Gutenberg block fires across every post and page. Fixing that single PHP ternary resolves the entire WordPress cluster.
What NVDA and VoiceOver announce
Invalid ARIA tokens (like aria-expanded='open'), broken IDREFs (aria-controls pointing to a nonexistent or unmounted ID), or mistyped booleans cause browsers and screen readers to silently drop interactive state announcements.
NVDA (Windows)
"Shipping & Returns FAQ, button" (collapsed/expanded state omitted due to invalid token)
"Shipping & Returns FAQ, button, expanded"
VoiceOver (macOS / iOS)
"Shipping & Returns FAQ, button" (state not exposed)
"Shipping & Returns FAQ, expanded, button"
Common questions
Why does echoing a PHP boolean into aria-expanded break axe-core?
How do I fix dangling aria-describedby attributes in WooCommerce checkout inputs?
Why do WordPress carousel plugins (Swiper/Slick) sometimes trigger aria-valid-attr-value?
Test a URL for aria-valid-attr-value
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.