Skip to content

Get embedded alt text from images#11135

Closed
joedolson wants to merge 11 commits intoWordPress:trunkfrom
joedolson:Import-alt-text-in-media-library-
Closed

Get embedded alt text from images#11135
joedolson wants to merge 11 commits intoWordPress:trunkfrom
joedolson:Import-alt-text-in-media-library-

Conversation

@joedolson
Copy link
Contributor

Based on https://gist.github.com/adamsilverstein/e9c9993d938eae80e559d9eda8c0fdcc

Addresses https://core.trac.wordpress.org/ticket/63895 and https://core.trac.wordpress.org/ticket/55535

Use of AI Tools

None (by me)


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @mathias7am.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props joedolson, audrasjb, huzaifaalmesbah, sabernhardt, valentingrenier, louischan, penelopeadrian.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@joedolson
Copy link
Contributor Author

@adamsilverstein I added a couple additional checks to protect against images with no XMP data or with invalid XML between the points, but there are probably other things that can be done here.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@joedolson joedolson marked this pull request as draft March 4, 2026 01:42
Copy link

@sabernhardt sabernhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To pass existing unit tests:

  1. The $value variable needs to be defined.
  2. Tests_Image_Meta::data_stream() metadata arrays need to include
    'alt' => '',

@joedolson joedolson requested a review from sabernhardt March 4, 2026 23:10
@joedolson joedolson marked this pull request as ready for review March 5, 2026 03:34
@valentin-grenier
Copy link

Just tested to import an image with "toto" as alternative text. The text is correctly retrieved and imported in the media library.

Config

OS : MacOS
WP: 7.0-beta2-20260305.033903

Image to test

metaeditor_204-200x300

Video screenshot

Screen.Recording.2026-03-05.at.10.28.21.mov

@louischance
Copy link

Just tried it and i seems to work correctly.

Steps I followed:

  1. I created the alt text meta data using an online tool (https://metaeditor.picvario.com/).
  2. I launched WordPress Playground with the pull request
  3. I imported the image in the media library (file attached below)
  4. The alt text is correctly imported.

image-with-alt-text

Environment:
Fedora Linux 43 (Workstation Edition)
WordPress development version (7.0-beta2-20260305.033903)

@padrian-06
Copy link

Test - WP Contributor day (Nice)

CONTEXT

  • OS : MacOS
  • WP : 7.0-beta2-20260305.033903
  • img attached got ALT = testing-alt

metaeditor_pexels-jonathanborba-36299843

TEST

SCREENCAST : https://jam.dev/c/918877cc-06c3-4be7-ad06-43f8d12dc526

RESULT

The alternative text appears in the media library in "Alternative Text" field

@mathias7am
Copy link

mathias7am commented Mar 5, 2026

Tested to import an image with alternative text. The text is correctly retrieved and imported in the media library.

Context

OS : Win11
Browser : Firefox
WP: 7.0-beta2-20260305.033903

Snapshot
Screenshot 2026-03-05 at 10-29-30 WordPress Playground

Copy link
Contributor

@audrasjb audrasjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good to go!

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 61841
GitHub commit: 823d9b3

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants