WordPress fix

Before and after

Broken — before
<?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>
Fixed — after
<?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>
Live preview

Fixed vs. broken example

Passes aria-valid-attr-value
Accessibility tree: role="button", expanded=true, controls=#demo-shipping-panel (valid WAI-ARIA 1.2 state & live DOM IDREF)

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.

Automated test

Playwright + axe-core check

tests/a11y-aria-valid-attr-value.spec.ts
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.

Screen readers

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)

Broken

"Shipping & Returns FAQ, button" (collapsed/expanded state omitted due to invalid token)


Fixed

"Shipping & Returns FAQ, button, expanded"

VoiceOver (macOS / iOS)

Broken

"Shipping & Returns FAQ, button" (state not exposed)


Fixed

"Shipping & Returns FAQ, expanded, button"

Common questions

Why does echoing a PHP boolean into aria-expanded break axe-core?
In PHP, echo true prints '1' and echo false prints an empty string ''. WAI-ARIA strictly requires the literal strings 'true' or 'false' for aria-expanded, aria-pressed, and aria-selected.
How do I fix dangling aria-describedby attributes in WooCommerce checkout inputs?
Only output aria-describedby when the helper description <span id='...-description'> is actually printed on the page; remove orphaned aria-describedby attributes if a plugin hides field hints.
Why do WordPress carousel plugins (Swiper/Slick) sometimes trigger aria-valid-attr-value?
Older carousel configurations write aria-live='on' or point aria-controls to slide IDs that haven't been assigned. Upgrade the slider library or set a11y options with valid 'polite' and live ID mappings.