WordPress fix

Before and after

Broken — before
<?php // template-parts/content-card.php (Broken: raw <img> with no alt attribute) ?>
<?php $thumb_url = get_the_post_thumbnail_url( get_the_ID(), 'medium_large' ); ?>
<?php if ( $thumb_url ) : ?>
  <img src="<?php echo esc_url( $thumb_url ); ?>" class="post-card__img" loading="lazy">
<?php endif; ?>
Fixed — after
<?php // template-parts/content-card.php (Fixed: wp_get_attachment_image + safe alt fallback) ?>
<?php
$thumb_id = get_post_thumbnail_id( get_the_ID() );
if ( $thumb_id ) {
  $stored_alt = trim( (string) get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) );
  $safe_alt   = '' !== $stored_alt ? $stored_alt : get_the_title();
  echo wp_get_attachment_image(
    $thumb_id,
    'medium_large',
    false,
    array(
      'class'   => 'post-card__img',
      'loading' => 'lazy',
      'alt'     => esc_attr( $safe_alt ),
    )
  );
}
?>
Live preview

Fixed vs. broken example

Passes image-alt
Accessibility tree: role="img", accessible name="Cobalt blue stoneware ceramic pour-over mug with matte handle"

Always provide meaningful alt text for informative photos and explicitly set alt="" (empty string) for purely decorative flourishes so screen readers skip them cleanly.

Automated test

Playwright + axe-core check

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

test("WordPress post thumbnails and archive images pass image-alt", async ({ page }) => {
  await page.goto("/blog/");
  const results = await new AxeBuilder({ page })
    .withRules(["image-alt"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A single custom template part like template-parts/content-card.php missing an alt attribute triggers image-alt on every WordPress blog archive and category page. A11yDrift deduplicates those into one WordPress template cluster.

Screen readers

What NVDA and VoiceOver announce

When an informative image lacks an alt attribute, screen readers either skip it silently or read out raw CDN filenames and hashes, blocking blind shoppers and readers from understanding products, charts, and editorial photos.

NVDA (Windows)

Broken

"graphic, cdn_shop_files_IMG_8842_v1731942.webp" (or skipped silently depending on verbosity)


Fixed

"Cobalt blue stoneware ceramic pour-over mug with matte handle, graphic"

VoiceOver (macOS / iOS)

Broken

"IMG_8842_v1731942.webp, image"


Fixed

"Cobalt blue stoneware ceramic pour-over mug with matte handle, image"

Common questions

Why does WordPress sometimes render alt="" even after I fill in the Media Library?
Existing Gutenberg Image blocks snapshot alt text inside post_content HTML at insertion time. Updating the Media Library later does not backfill older posts unless you update the block or filter render_block.
Should I set every missing WordPress image alt to the filename?
Never use filenames like IMG_4821.jpg as alt text—that degrades screen-reader usability even though it silences automated presence checks. Write concise human descriptions or fall back to meaningful post/product context.
How do I handle decorative background flourishes in WordPress block themes?
In Gutenberg's Image block inspector, leave the Alternative Text field blank so WordPress outputs alt="" for purely decorative graphics, or apply non-essential visuals via CSS background-image.