Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#11846 closed defect (bug) (fixed)

Alt text for images wrong or empty in wp_get_attachment_image()

Reported by: kallewangstedt Owned by:
Milestone: 3.0 Priority: normal
Severity: major Version: 2.9
Component: Media Keywords: has-patch
Focuses: Cc:


When wp_get_attachment_image() is called, it generates the alt-text from the post_excerpt field instead of the (new) postmeta field with meta_key "_wp_attachment_image_alt". This causes the alt text to not be set even though the media editor clearly states that the "Alternate text" field is being used as alt text for the image.

I have attached a patch that corrects this by calling get_post_meta() instead of post_excerpt inside the function.

As a fallback it would be good to expand the function to check if there is an alt-text entry, and if not use the caption (post_excerpt) field instead, or if only the Title is set use that.

The alt text should not be empty at all.

Attachments (1)

media.php.diff (553 bytes) - added by kallewangstedt 12 years ago.
Patch for wp_get_attachment_image()

Download all attachments as: .zip

Change History (5)

12 years ago

Patch for wp_get_attachment_image()

#1 @scribu
12 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0

#2 @maorb
12 years ago

  • Cc maorb added

Thanks for your patch, I've just encountered this problem of missing alt text using the wp_get_attachment_image function, and didn't understand where have they disappeared...

Will this bug be fixed on ver 3.0?

#3 @kallewangstedt
12 years ago

It is NOT fixed in 3.0 as far as I can tell.

#4 @dd32
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [14145]) Use Alt Text for Image alt caption (Falling back to Caption, and finally title) in wp_get_attachment_image() and subsequently, WordPress Galleries. Props kallewangstedt for initial patch. Fixes #11846

Note: See TracTickets for help on using tickets.