Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#23103 closed enhancement (fixed)

Image caption shortcode without a width is lost

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

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)

#1 @SergeyBiryukov
14 years ago

  • Version 3.5 → 3.4

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

#2 @trepmal
14 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" />

#3 follow-ups: @azaozz
13 years ago

  • Milestone Awaiting Review
  • Resolution → worksforme
  • Status new → 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.

#4 in reply to: ↑ 3 @nacin
13 years ago

  • Milestone → Future Release
  • Priority normal → low
  • Summary Non image caption shortcode lost when switching from text to visual editor and back → Image caption shortcode without a width is lost
  • Type defect (bug) → 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?

#5 @SergeyBiryukov
13 years ago

  • Resolution worksforme
  • Status closed → reopened

#6 in reply to: ↑ 3 ; follow-up: @Clorith
13 years 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?

#7 in reply to: ↑ 6 @azaozz
13 years ago

  • Milestone Future Release → 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.

#8 @azaozz
13 years ago

  • Owner set to azaozz
  • Resolution → fixed
  • Status reopened → 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.