Opened 16 years ago
Closed 16 years ago
#8732 closed defect (bug) (fixed)
Empty Alt Text in wp_get_attachment_image()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | 2.7 |
Component: | Media | Keywords: | has-patch tested |
Focuses: | Cc: |
Description
wp_get_attachment_link() calls wp_get_attachment_image() which unconditionally returns an empty alt attribute at line 536:
$html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" alt="" />';
This is wrong because wp-admin/media.php?action=edit says under the Caption field, "Also used as alternate text for the image". Therefore, wp_get_attachment_image() should be returning the attachment caption.
fwiw, I believe this also affected the 2.6 branch. I decided to report now that I see it's not fixed yet.
Attachments (1)
Change History (12)
#2
@
16 years ago
Also reported #8763 and updated the workaround above as follows:
str_replace('alt=""', 'alt="'.attribute_escape(get_the_excerpt()).'"', wp_get_attachment_link($post->ID, array(450, 800))
#3
@
16 years ago
- Keywords has-patch tested added
- Owner changed from anonymous to Sam_a
- Status changed from new to assigned
Attached patch wp_get_attachment_image_alt.diff
works in trunk (revision 10347) with no errors.
Patch uses attachment excerpt as alt text ("caption" field in WP 2.6 media interface) if non-empty; otherwise it uses the attachment title. (There was no "caption" field before 2.6, so attachments created then probably have empty excerpts.)
I also added a new filter hook, wp_get_attachment_image_alt
, so people can choose some other alt text if they like.
#5
@
16 years ago
- Component changed from General to Media
- Owner changed from Sam_a to azaozz
- Status changed from assigned to new
#6
@
16 years ago
New patch wp_get_attachment_image_alt.diff:
- Adds
alt
attribute (from attachment caption/alternate text field) - Adds
title
attribute (from attachment title field) - Adds general
wp_get_attachment_image_attributes
filter hook allowing plugins to alter attributes (except height, width) or add new ones
This patch treats title and caption fields separately, and the filter hook (on $attr array) is more flexible.
Works for me without errors in revision 10347.
Hopefully Andrew may find it useful. :)
#7
@
16 years ago
Sam_a, I think the attribute quoting needs to be changed back to double quotes for consistency.
#8
@
16 years ago
I think the attribute quoting needs to be changed back to double quotes for consistency.
Shouldn't really matter either way.. Use the right quotation mark where needed.
I do question if the PHPDoc will be reconised in that form though, I'm not too sure if the parser would pick it up, or reconise its to do with that filter at all.
You might be better off mentioning the filters params in the functions PHPDoc instead.
@
16 years ago
Adds ALT and TITLE attributes to img output; adds general filter hook for most attributes
Current workaround