WordPress.org

Make WordPress Core

Opened 10 months ago

#40299 new defect (bug)

Removing width attribute on an image with a caption removes entire caption

Reported by: catchmyfame Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Media Keywords:
Focuses: Cc:

Description

If you insert an image with a caption into the visual editor, it will create code like:

[caption id="attachment_12345" align="alignnone" width="150"]<img class="wp-image-12345 size-thumbnail" src="https://www.example.com/wp-content/uploads/2017/03/image.png" alt="" width="150" height="150" /> My caption[/caption]

If you switch from the visual editor to the text editor and remove the width attribute of the image to get:

[caption id="attachment_12345" align="alignnone" width="150"]<img class="wp-image-12345 size-thumbnail" src="https://www.example.com/wp-content/uploads/2017/03/image.png" alt="" height="150" /> My caption[/caption]

And then either update the post, or switch back to the visual editor, the caption is stripped and only the image remains:

<img class="wp-image-12345 size-thumbnail" src="https://www.example.com/wp-content/uploads/2017/03/image.png" alt="" height="150" />

Removing the height attribute doesn't appear to cause the same behavior. I don't believe that removing the width attribute on the image should result in both the caption being stripped and the [caption] shortcode being removed.

I'm not sure but this might be related to https://core.trac.wordpress.org/changeset/27426 and https://core.trac.wordpress.org/ticket/23103

Change History (0)

Note: See TracTickets for help on using tickets.