Skip to content

WordPress image SEO — alt text, lazy load, and file naming

WordPress image SEO has three operational levers — alt text, lazy loading, and file naming. What matters for ranking and Core Web Vitals, and the fix workflow.

Image SEO on WordPress used to mean “set alt text.” Now it includes lazy loading (which affects LCP), responsive srcset (which affects bandwidth), file naming (which affects Google Images), and format selection (WebP/AVIF for Core Web Vitals). Most WordPress sites get the alt text question right and miss the rest. The fix workflow is mechanical once you know what to audit.

What’s happening

Every WordPress image insertion via the block editor produces an <img> tag with src, srcset, sizes, width, height, alt, and loading attributes. Each one affects SEO or Core Web Vitals differently. WordPress core handles srcset, sizes, and loading="lazy" automatically since WordPress 5.5. Alt text and file names are author responsibilities — the WordPress media library captures alt text when you upload, but most editors skip the field. File names are baked at upload time; once uploaded, renaming is a database operation.

How to verify

From any host with curl:

curl -s https://example.com/some-post/ | grep -o '<img[^>]*>' | head -10
curl -s https://example.com/some-post/ | grep -oE '<img[^>]*loading="[^"]*"' | head -10
curl -sI https://example.com/wp-content/uploads/2024/01/sample-image.webp

You want every <img> to have alt, loading, srcset, and width+height attributes. The image file should be served as WebP or AVIF for modern browsers (the SEO plugin or a dedicated optimizer like ShortPixel handles this). From WP-CLI:

wp db query "SELECT COUNT(*) FROM wp_postmeta WHERE meta_key='_wp_attachment_image_alt' AND meta_value!=''"
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type='attachment' AND post_mime_type LIKE 'image/%'"

The ratio tells you what percentage of images have alt text.

The fix

  1. Alt text. Every content image needs descriptive alt text. Two common mistakes: copying the filename (“IMG_4521.jpg” becomes alt text), and stuffing keywords. Alt should describe what’s in the image for a user who can’t see it. Decorative images (visual flourishes, dividers) should have empty alt (alt=""), not missing alt. WordPress block editor has the alt field; train editors to use it.

  2. Bulk fix existing images. Run a report of images without alt text:

    wp db query "SELECT p.ID, p.post_title, p.guid FROM wp_posts p LEFT JOIN wp_postmeta m ON p.ID=m.post_id AND m.meta_key='_wp_attachment_image_alt' WHERE p.post_type='attachment' AND p.post_mime_type LIKE 'image/%' AND (m.meta_value IS NULL OR m.meta_value='') LIMIT 50"

    Update via WP-CLI: wp post meta set <id> _wp_attachment_image_alt "Descriptive alt text".

  3. Lazy loading. WordPress 5.5+ adds loading="lazy" to images below the fold automatically. The first image (typically the hero image) should NOT lazy-load — it’s the LCP element, and lazy-loading it delays LCP by 200-500ms. Themes occasionally lazy-load everything, killing Core Web Vitals on the WordPress home page. Verify: the hero image should have loading="eager" or no loading attribute.

  4. File naming. Upload files with descriptive, hyphen-separated names: kitchen-cabinet-installation.jpg not IMG_4521.jpg. WordPress preserves the upload filename in the URL. For existing images, renaming requires a plugin (Media File Renamer) or manual database operation — usually not worth it unless the site is small.

  5. Width and height attributes. Every <img> should have width and height attributes for layout stability (CLS in Core Web Vitals). WordPress block editor adds these automatically. Hand-coded theme templates often miss them — audit theme files: grep -rn '<img' wp-content/themes/<active>/ | grep -v 'width='.

  6. Modern formats (WebP/AVIF). Modern image formats give 20-50% smaller files at equivalent quality. WordPress 6.0+ supports WebP uploads natively. For AVIF and automated conversion, use a plugin (ShortPixel, Imagify, Optimole) or a CDN-level transformer (Cloudflare Polish, Bunny Optimizer). Stack Harbor’s enterprise WordPress baseline uses CDN-level transformation rather than WordPress-side conversion — it’s faster and doesn’t bloat the media library.

  7. Image sitemaps. Yoast and Rank Math both emit image sitemaps automatically — entries in image-sitemap.xml help Google Images discovery. Verify: curl -s https://example.com/image-sitemap.xml | head. If empty, the SEO plugin’s image sitemap setting is off.

  8. Avoid figcaption for keyword stuffing. Captions should describe the image for users, not pack keywords. Google ignores keyword-stuffed captions and may flag them.

  9. Don’t serve oversized images. A 4000px-wide hero image on a 1200px-wide design wastes bandwidth and hurts LCP. WordPress’s srcset should serve the right size — verify with browser DevTools > Network > image request size.

Stack Harbor handles image optimization as part of enterprise WordPress operations. Start the conversation when your WordPress Core Web Vitals score drops because of an image-heavy template.