Auto Alt Text From File Name – Made by Saad

By Mohamed Saad

40+ active installationsVersion 1.1.0

Fills empty alt text from the image's file name, and captions other media on request. Skips meaningless names such as IMG_1234.

Description

Auto Alt Text From File Name fills the alt text of new images from their file name, and can caption audio, video and documents the same way. It is a starting point for sites whose files already have descriptive names. It is not a substitute for alt text written by a person.

red-running-shoes.jpg becomes "Red running shoes". `IMG_1234.jpg` gets nothing, because the name says nothing about the picture.

What it does

  • Fills alt text for new images when the field is empty. Existing alt text and captions are never overwritten.
  • Optionally writes a caption for audio, video and documents.
  • Mass Update fills empty fields in the existing Media Library and reports how many items it changed and skipped.
  • Uses the original file name: no “-scaled”, “-rotated” or edit numbers, no “-1” for a second copy, accents kept.
  • Skips camera, screenshot, messenger and number-only names.
  • Leaves site icons, logo and header crops alone, and keeps WordPress’s own alt text for the site logo.
  • Alt text added later by an importer replaces the generated text.
  • Templates per file type and per format, for example {filename} or Product photo: {filename}. An empty template writes nothing.
  • No account, no API key and no outside requests.

For developers

  • aatf_generated_text filters the final text. Return an empty string to skip the file. Arguments: text, attachment ID (0 while a caption is prepared before the attachment exists), source name.
  • aatf_junk_patterns filters the list of regular expressions that mark a name as meaningless.

Installation

  1. In WordPress, go to Plugins > Add Plugin and search for “Auto Alt Text From File Name”, or upload the plugin folder to /wp-content/plugins/madebysaad-auto-alt-text-from-filename.
  2. Activate the plugin through the Plugins screen.
  3. Go to Settings > Alt Text Generator to adjust the templates and run Mass Update.

FAQ

Does this work with existing files?

Yes. Mass Update on the settings page fills empty alt text and captions in the Media Library. Alt text that was cleared on purpose is skipped unless you tick the box to fill it too.

Will it overwrite my existing alt text or captions?

No. It only fills empty fields.

What happens when I delete the plugin?

Alt text and captions stay. With “Delete this plugin’s settings” ticked, only the plugin’s own settings and its record of the text it wrote are removed.

I updated from 1.0.0. Does my text change?

No. Sites that used 1.0.0 keep their templates and their output. The settings page offers to switch to the new defaults: plain text, first letter capitalised, meaningless names skipped and the original file name used.

Does it fix text that 1.0.0 wrote?

Mass Update can rewrite alt text that 1.0.0 built from an internal file name, such as “… Scaled”. Tick the repair box before you run it. Only text that matches exactly what 1.0.0 wrote is changed.

Does it change images already placed in posts?

No. The block editor copies alt text into the post when an image is inserted, so later changes in the Media Library do not reach those posts.

Screenshots

Changelog

1.1.0

  • Fixed: with “Cleanup on Uninstall” ticked, deleting the plugin removed all alt text and captions from the Media Library, not only generated ones. Uninstall now removes only the plugin’s settings, on every site of a network.
  • Fixed: Mass Update wrote “Scaled”, “Rotated” and edit numbers into alt text. It now uses the original file name, and can repair text that 1.0.0 wrote this way.
  • Fixed: Mass Update refilled alt text that was cleared on purpose. It now skips it and reports the count.
  • Fixed: alt text added by an importer after the upload was hidden by the generated text.
  • Fixed: backslashes in templates were dropped, an emptied template stored empty alt text, and an alt text of “0” was replaced.
  • Fixed: a caption for a document or audio file saved the upload a second time.
  • Changed: Mass Update reads the library in pages and checks the user’s rights itself.
  • New for new installs: plain templates, first letter capitalised, meaningless names skipped, original file names used. Existing sites keep their output and can switch on the settings page.
  • New: site icons, logo and header crops get no generated text, and the site logo keeps WordPress’s own alt text.
  • New: two filters, translatable strings and labels for every settings field.
  • Readme now describes only what the plugin does.

1.0.0

  • First release.