Add bulk "Generate Alt Text" action to Media Library#330
Add bulk "Generate Alt Text" action to Media Library#330dkotter merged 19 commits intoWordPress:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #330 +/- ##
=============================================
+ Coverage 64.33% 65.82% +1.48%
- Complexity 753 763 +10
=============================================
Files 53 53
Lines 3827 3859 +32
=============================================
+ Hits 2462 2540 +78
+ Misses 1365 1319 -46
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for catching this @jeffpaul — the truncation comes from a hard limit in the Ability class (Alt_Text_Generation.php:207-209). This affects all alt text generation (individual + bulk). The The system instruction already soft-limits output to 125 characters ("when possible"). Per WCAG image alt text guidelines, alt text should be "succinct", not artificially truncated. A full 150-character description serves users better than one cut at 122 characters with Should we remove the hard truncation and rely on the prompt guidance? |
Yeah, this limit has been in place since the original PR (see here). I'm not sure on the "why" here though I'd suggest we just remove that limit. I think it's fine to suggest a limit in our system instructions (though LLM's are notorious for not following length requirements) but I don't think we should truncate ourselves |
|
Removed the hard 125-character truncation in |
dkotter
left a comment
There was a problem hiding this comment.
Tested and overall works good, left a handful of comments. Also would be great to get E2E tests here to cover these changes
…t and improve error handling in bulk processing
dkotter
left a comment
There was a problem hiding this comment.
Left a few more comments and would still want some E2E tests here before we merge this
includes/Experiments/Alt_Text_Generation/Alt_Text_Generation.php
Outdated
Show resolved
Hide resolved
includes/Experiments/Alt_Text_Generation/Alt_Text_Generation.php
Outdated
Show resolved
Hide resolved
|
Added E2E tests in |
… details tests: fix script path in Alt_Text_GenerationTest and update experiment name in E2E tests
|
Looks like some new failing E2E tests here (outside of the known failures we have that are being fixed elsewhere). I think the issue here is we toggle over to the list media view and then we don't toggle back to the grid view, so those tests are failing. I can take a look once we have the existing tests fixed up in a separate PR as it's hard to parse through that right now |
|
@dkotter All CI tests have passed successfully. I believe this is ready to be merged. |

What?
Closes #239
Adds a "Generate Alt Text" bulk action to the WordPress Media Library (list view). When one or more images are selected and the action is applied, alt text is generated sequentially for each image using the existing
ai/alt-text-generationability and saved directly to each attachment via the REST API. A live progress notice is shown while processing and replaced with a summary on completion.Why?
Alt text generation for individual images already existed in the media modal and attachment edit screen, but there was no way to process multiple images at once. This extends the feature to support bulk workflows, addressing the remaining item from issue #239.
How?
PHP (
includes/Experiments/Alt_Text_Generation/Alt_Text_Generation.php):"Generate Alt Text"in the Media Library bulk actions dropdown via thebulk_actions-uploadfilter.handle_bulk_actions-upload: filters selected IDs to image attachments only, then appendsai_bulk_alt_text=1andai_attachment_ids=<ids>to the redirect URL.alt-text-generation-bulkscript with the attachment IDs and awp_restnonce.JavaScript (
src/experiments/alt-text-generation/bulk.ts):DOMContentLoaded, reads localized data and injects a dismissible WP admin notice.runAbility('ai/alt-text-generation', { attachment_id })utility for each.apiFetchto/wp/v2/media/:id.Build (
webpack.config.js):experiments/alt-text-generation-bulkentry point.Tests (
tests/Integration/Includes/Experiments/Alt_Text_Generation/Alt_Text_GenerationTest.php):Use of AI Tools
Implementation was planned with assistance from Claude Code (Anthropic). All code was reviewed, tested, and validated.
Testing Instructions
upload.php).upload.phpand a progress notice appears:"Generating alt text: 0 / N…"."Alt text generated for all N images.".Testing Instructions for Keyboard
Spaceto check image rows.Enter.×) is reachable by keyboard.Screenshots or screencast
Screen.Recording.2026-03-20.at.10.59.33.PM.mov