WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 18 months ago

#23103 closed enhancement (fixed)

Image caption shortcode without a width is lost

Reported by: mark-k Owned by: azaozz
Milestone: 3.9 Priority: low
Severity: normal Version: 3.4
Component: Editor Keywords:
Focuses: Cc:

Description

  1. Add the line in text editor
    [caption caption="test" width="300"]Checkuot this text[/caption]
    
  1. switch to visual editor
  1. switch back to text and you get
    <dl class="wp-caption alignnone" id="" style="width: 310px;"><dt class="wp-caption-dt">Checkuot this text</dt><dd class="wp-caption-dd">test</dd></dl>
    

Change History (8)

comment:1 @SergeyBiryukov3 years ago

  • Version changed from 3.5 to 3.4

Reproduced in 3.4 as well. In 3.3 and earlier, only "Checkout this text" remains.

comment:2 @trepmal3 years ago

Seems related, though I haven't checked pre-3.5. If you have a normal captioned image, but remove the width attribute, for example:

[caption id="attachment_67" align="alignnone" width="300"]
<img class="size-medium wp-image-67" alt="caption" src="http://local.dev/stable/wp-content/uploads/2012/11/cropped-tree-300x149.png" height="149" /> caption[/caption]

Then switching to visual and back strips away the shortcode entirely leaving you with:

<img class="size-medium wp-image-67" alt="caption" src="http://local.dev/stable/wp-content/uploads/2012/11/cropped-tree-300x149.png" height="149" />

comment:3 follow-ups: @azaozz19 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

The caption shortcode is specifically for adding captions to images. If no image exists the shortcode is removed. Removing it works as expected now, doesn't leave behind any html tags.

If you have a normal captioned image, but remove the width ...

Yes, the captions require the width attribute. We probably can recreate the caption width from the image tag width, but don't see why the width was removed from the caption in the first place.

comment:4 in reply to: ↑ 3 @nacin19 months ago

  • Milestone set to Future Release
  • Priority changed from normal to low
  • Summary changed from Non image caption shortcode lost when switching from text to visual editor and back to Image caption shortcode without a width is lost
  • Type changed from defect (bug) to enhancement

Replying to azaozz:

Yes, the captions require the width attribute. We probably can recreate the caption width from the image tag width, but don't see why the width was removed from the caption in the first place.

I think it would be reasonable to do this. Wouldn't it also make it easier to insert a caption shortcode manually?

comment:5 @SergeyBiryukov19 months ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

comment:6 in reply to: ↑ 3 ; follow-up: @Clorith18 months ago

Replying to azaozz:

Yes, the captions require the width attribute. We probably can recreate the caption width from the image tag width, but don't see why the width was removed from the caption in the first place.

I believe the width is removed in regard to responsive designs. Both the height and width attribute in both images inserted and the caption shortcode makes this a challenge.

Couldn't we set the width of it to the captioned image wrapper, and make it filterable?

And with image sizes, are the width and height attributes required when Full Size is selected? I can see the use for Thumbnail, Medium etc, but it just seems redundant on the full one?

comment:7 in reply to: ↑ 6 @azaozz18 months ago

  • Milestone changed from Future Release to 3.9

Replying to Clorith:

This affects only displaying the captions inside the Visual editor. For the front-end the HTML can be overridden with the 'img_caption_shortcode' filter.

The width and height attributes on <img> are considered HTML best practice as they let the browser allocate the space for the image before it has started downloading and prevent all the page's content from jumping and shifting, especially on slower connections.

comment:8 @azaozz18 months ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from reopened to closed

In 27426:

TinyMCE: when parsing [caption] and the width attribute is missing, recreate it from the image tag width, fixes #23103

Note: See TracTickets for help on using tickets.