Image SEO: Automatic Alt and Title Attributes

Fill missing image alt and title attributes from a format with the image title, file name, post title and site name. Off by default, nothing written to the database.

7 min read
On this page
  1. Switch it on
  2. The variables
  3. Which images are filled
  4. Missing alt and empty alt are different
  5. Where it runs
  6. Check the result
  7. Good formats, and ones to avoid
  8. Coming from another SEO plugin
  9. For developers
  10. Performance
  11. FAQ
  12. Does this write alt text into my Media Library?
  13. Is generated alt text as good as written alt text?
  14. Why did my images not get alt text after I switched it on?
  15. Does it use AI or credits?
  16. Will it fix "images missing alt text" in an audit?
  17. Related reading

Hydrogen SEO can fill in the alt and title attributes of images that lack them, using a format you write once. The text is added as each page is sent to a visitor: nothing is saved to your Media Library or your posts, and switching the feature off returns every image to how it was. Both switches are off by default, free, and need no account. Version 0.0.30 rebuilt the feature with image-specific variables, a separate choice for images that have an empty alt="", and coverage of featured, gallery and shop images.

This is a fallback. A format can produce "Blue ceramic dripper" from a file name, but it cannot know what the picture shows or why it is on the page. For alt text written per image, by hand or with AI, see image alt text.

Switch it on

  1. Open Hydrogen SEO → General and open the Images section.
  2. Switch on Add Missing ALT Attributes, Add Missing TITLE Attributes, or both. With the first one on, the Also Fill Empty Alt (alt="") switch appears under it; it is explained below.
  3. Each has a format field underneath. Leave the default or type your own; type @ to insert a variable.

The General screen saves a moment after you stop typing. Pages show the result from their next load, once any page cache has been cleared.

The variables

VariablePrintsExample
%image_title%The image's title in the Media Library. For an image with no title, or one that is not in the library, the file name as wordsPour-over coffee on a scale
%filename%The file name as words: extension, size suffixes such as -1024x768 and -scaled removed, dashes and underscores turned into spaces, first letter capitalisedpour-over_coffee-1024x768.jpg becomes "Pour over coffee"
%post_title%The title of the post the image is shown on. For a featured image in a list of posts, the post that image belongs toHow to Brew Pour-Over Coffee
%site_name%Your site's nameBrew Notes

Both formats default to %image_title%. WordPress names every upload after its file, so an untouched title such as pour-over-coffee is read as words too, and a title someone typed is used exactly as written.

These four are the variables the picker offers. Formats saved by earlier versions keep working: %title% in an alt format still means the post title, %file_name% still means the file name, and the common title variables an older format may contain, such as the separator, the tagline, the author name and the category, are still filled in.

Anything else between percent signs is removed, so visitors never see a raw %variable%, and a separator left dangling by an empty value is trimmed: %image_title% - %site_name% prints "Brew Notes", not "- Brew Notes", when the first variable has no value. If a format prints nothing at all for an image, the default %image_title% is used for that image instead.

Which images are filled

Alt. For an image in a post's content, the order is:

  1. The image's Alternative Text from the Media Library, when it has one. Content often holds an older, emptier copy of the alt than the library does, and this picks up the newer text.
  2. Otherwise, the Alt Attribute Format.

For images WordPress prints itself, such as featured images, galleries, product images and most page builder images, WordPress has already used the library's alt text, so the format is applied only when that is empty.

Title. An image with no title attribute, or an empty one, gets the Title Attribute Format. An existing title is never replaced.

Images that are not in your Media Library, such as ones hotlinked from another address, are covered as well, using the file name from the image's address.

Never given alt text. An image marked role="presentation", role="none" or aria-hidden="true" has been declared decorative in its own markup, so no alt text is generated for it, whatever the switches say.

Missing alt and empty alt are different

An image can lack alt text in two ways:

  • No alt attribute at all. Usually hand-written HTML or old imported content.
  • An empty alt="". This is what WordPress prints when the Alternative Text field was left blank, and it is also the correct markup for a decorative image that screen readers should skip.

HTML cannot tell a forgotten alt from a deliberate one, so the choice is yours. Add Missing ALT Attributes on its own fills only images with no alt attribute. Also Fill Empty Alt extends it to alt="":

Your siteSuggested setting
Alt text was rarely written, and few images are decorativeBoth switches on. Most images WordPress prints have alt="", so this is what makes the feature reach them
Editors use empty alt on purpose for decorative imagesAlso Fill Empty Alt off, and write alt text for the images that need it in the Media Library
A mixtureBoth on, with decorative images marked role="presentation" in their markup, or excluded with the developer filter below

Sites that had Add Missing ALT Attributes on before 0.0.30 keep the earlier behaviour, which filled empty alt too, until the new switch is saved.

Where it runs

On the pages visitors and search engines load. It does not run in wp-admin, in the editor, in feeds or in REST API responses, and it never writes to the database. In the Media Library, an image with no alt text still shows an empty Alternative Text field, which is accurate: the field is empty, and the page is given a stand-in.

Images that a lazy-loading plugin has rewritten are handled, with the file name read from the image's real address.

Check the result

Open a post, right-click an image and choose Inspect, or view the page source and find the <img> tag. With the default formats and an image uploaded as pour-over-coffee.jpg:

html
<img src="/wp-content/uploads/pour-over-coffee-1024x683.jpg" alt="Pour over coffee" title="Pour over coffee" />

If nothing changed, clear your page cache, and check whether the image already had an alt (it is left alone) or an empty one (see the section above).

Good formats, and ones to avoid

FormatResultComment
%image_title%Pour over coffeeThe default. Describes the image, if the file was named sensibly
%image_title%, %post_title%Pour over coffee, How to Brew Pour-Over CoffeeAdds context when file names are terse
%post_title%How to Brew Pour-Over CoffeeEvery image in the post gets identical alt text. Acceptable for a single featured image, poor for a post with ten photos
%post_title% %site_name% best coffee guide(the same phrase on every image)Keyword stuffing. It helps nobody and reads as noise in a screen reader

The quality of the result depends on your file names. IMG_4032.jpg becomes "IMG 4032", which is no better than nothing. If your uploads look like that, rename files before uploading or write real alt text.

A note on title: browsers show it as a tooltip on hover, and search engines give it little weight. Leaving Add Missing TITLE Attributes off is a reasonable default. It exists for sites whose audits or house rules ask for the attribute.

Coming from another SEO plugin

Tools → Import SEO Data brings the alt and title switches and their formats across from plugins that have the feature. Where the old plugin also filled empty alt attributes, Also Fill Empty Alt is switched on to match. Variables that have no image equivalent are left out of the imported format and listed in the report. See switch from another SEO plugin.

For developers

hydrogen_seo_fill_missing_image_alt decides per image whether alt text is generated. Return false for images whose empty alt is deliberate:

php
add_filter( 'hydrogen_seo_fill_missing_image_alt', function ( $fill, $img_tag, $attachment_id ) {
	// Leave images marked as decorative alone.
	return false === strpos( $img_tag, 'is-decorative' ) ? $fill : false;
}, 10, 3 );

$img_tag is the <img> tag for images in content and an empty string for images WordPress prints itself; $attachment_id is 0 for images that are not in the Media Library.

Performance

With both switches off, no code is attached to your images. With one on, each image is handled as WordPress prints it, a variable is worked out only if the format uses it, and the titles involved come from data WordPress has already loaded for the page.

FAQ

Does this write alt text into my Media Library?

No. The Media Library and your post content are not changed. To store alt text on the images themselves, use the AI or manual routes in image alt text.

Is generated alt text as good as written alt text?

No. It is better than a missing attribute when file names are descriptive, and it is the same words a visitor would get from the file name. Images that carry meaning deserve a written description.

Why did my images not get alt text after I switched it on?

Most likely they have an empty alt="", which is left alone unless Also Fill Empty Alt is on. The other usual cause is a cached page.

Does it use AI or credits?

No. It is text substitution and works with no account. Generate Alt Text with AI on Upload, in the same section, is the feature that uses credits.

Will it fix "images missing alt text" in an audit?

For audits that read the published page, yes, since the attribute is present there. The SEO score reads the post's saved content, so it continues to count images whose alt was never written.

Was this page helpful?
Still stuck? Contact support