[wp-trac] [WordPress Trac] #39912: Image empty alt attributes get stripped out when editing the image details from a post

WordPress Trac noreply at wordpress.org
Sat Feb 18 17:16:04 UTC 2017


#39912: Image empty alt attributes get stripped out when editing the image details
from a post
---------------------------+-----------------------------
 Reporter:  afercia        |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  high           |  Milestone:  Awaiting Review
Component:  Media          |    Version:
 Severity:  normal         |   Keywords:  needs-patch
  Focuses:  accessibility  |
---------------------------+-----------------------------
 When an image has a decorative purpose, it's extremely important for
 accessibility that the image has an empty alt attribute `alt=""`. In
 absence of an empty alt attribute, assistive technologies won't assume the
 image is just decorative and will try to read out "something". In most of
 the cases they read out the image file path or part of it, i.e. the
 filename.

 Turns out, when editing the details of an image inside a post, empty alt
 attributes get stripped out when updating the details.

 Seems to me this is not specific to 4.7 but happens also in some of the
 previous versions, under different conditions. Worth reminding the alt
 attribute fallback to the title was recently removed, and this is one of
 the reasons for the different behaviour across different versions.

 To reproduce in WordPress 4.7:

 - edit a post
 - insert an image with an empty alt attribute

 The markup inserted in the post will be something like this:
 `<img class="alignnone size-full wp-image-3020" src="http://.../wp-
 content/uploads/2017/01/image.jpg" alt="" width="1200" height="800" />`

 - then click on the image and click on the "Edit" pencil icon in the
 inline image toolbar
 - the "Image Details" modal opens
 - change some image property, for example set the alignment to "right"
 - click the "Update" button in the modal

 The updated markup in the post will be:
 `<img class="alignright wp-image-3020 size-full" src="http://.../wp-
 content/uploads/2017/01/image.jpg" width="1200" height="800" />`

 To reproduce in WordPress 4.6 and 4.5:
 - repeat all the steps above but make sure that also the "Title" of the
 image is empty. When both the title and the alt text fields are empty, the
 empty `alt=""` gets stripped out

 WordPress 4.4:
 Seems to me the empty alt attribute is always preserved, which is the
 correct behaviour.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39912>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list