[wp-trac] [WordPress Trac] #34635: WordPress image's title is not alt

WordPress Trac noreply at wordpress.org
Mon Nov 9 22:40:29 UTC 2015


#34635: WordPress image's title is not alt
--------------------------+--------------------------------------------
 Reporter:  odie2         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  4.3
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  ui, accessibility, javascript
--------------------------+--------------------------------------------
Changes (by afercia):

 * keywords:  2nd-opinion => needs-patch
 * focuses:  ui, accessibility => ui, accessibility, javascript
 * version:  4.3.1 => 4.3


Comment:

 As far as I see, the real problem is when inserting images into a post. To
 reproduce:
 - have one image in the media library '''with no alt attribute''' and
 title, say, "456789.jpg"
 - edit a post and press the Add Media button
 - in the media modal, select the "456789.jpg" image
 - in the right sidebar, under "Attachment Details" the image has a title
 '''and an empty alt attribute'''
 - press the button "Insert into post"
 - the image will be inserted and the alt attribute will be set to
 "456789.jpg". Worth noting that's not what the UI just showed me since the
 alt attribute in the attachment details was empty and I wanted to leave it
 empty intentionally

 Looks like in `media-editor.js` the alt attribute is forced to be always
 populated with some value, if there's a suitable value to use:
 {{{
 // Generate alt fallbacks and strip tags.
 if ( 'image' === props.type && ! props.alt ) {
         props.alt = props.caption || props.title || '';
         props.alt = props.alt.replace( /<\/?[^>]+>/g, '' );
         props.alt = props.alt.replace( /[\r\n]+/g, ' ' );
 }
 }}}
 So if there's no alt attribute, it will try the caption first and then the
 title. If both are empty, the alt attribute will be empty. This could work
 when the title (or the caption) have a meaningful text but when not,
 having images with an alt attribute like "456789.jpg" should be definitely
 avoided.
 Maybe this fallback would need some re-thinking, there's also the chance
 to have the caption and alt attribute set to the same value, which is a
 bit redundant.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34635#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list