Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#31053 closed enhancement (fixed)

HTML5 caption disregards img_caption_shortcode_width filter

Reported by: trysmudford's profile trysmudford Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.1
Component: Media Keywords: has-patch
Focuses: Cc:

Description

In /wp-includes/media.php in the img_caption_shortcode function, the img_caption_shortcode_width filter is applied after the HTML5 caption has been returned, thus not setting the developer specified width.

I propose lines 875 to 879 should be moved above the HTML5 conditional on line 853 and it should only apply the $style variable, not hard-code the style attribute onto the element itself.

Attachments (1)

31053.diff (1.7 KB) - added by joemcgill 9 years ago.
Adds support for 'img_caption_shortcode_width' filter on HTML5 captions

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
9 years ago

the img_caption_shortcode_width filter is applied after the HTML5 caption has been returned, thus not setting the developer specified width.

That's intentional, see [27668].

#2 @TheDeadMedic
9 years ago

Just to jump in - that seems crazy.

So let me get this straight. If a theme author does not define HTML5 captions, they have the power to override the inline width, or even remove the inline style completely.

Yet with HTML5, they have nothing (at least not without overriding the shortcode handler).

I completely understand the removal of the 10 pixel padding, but not bypassing the filter entirely.

If anything, defining HTML5 caption support is an indication that the theme is responsive and far more likely to apply granular control over images and captions.

#3 @TheDeadMedic
9 years ago

  • Type changed from defect (bug) to enhancement

Is there no comment on this? If backwards-compat is an issue, introduce a new filter. WordPress should not be forcing theme authors to override the shortcode handler simply to remove the inline style width.

@joemcgill
9 years ago

Adds support for 'img_caption_shortcode_width' filter on HTML5 captions

#4 @joemcgill
9 years ago

  • Keywords has-patch dev-feedback added

I agree, the current behavior is less than ideal. Currently, if someone wants to use the HTML5 markup for image captions and filter out the inline style attribute, they would have to hook in early on at the img_caption_shortcode filter and recreate the HTML wrapper themselves. I've added a patch that would respect the removal of the extra 10px from the caption width from HTML5 captions, while still allowing the img_caption_shortcode_width filter to apply.

#5 @wonderboymusic
9 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 4.4

Yep

#6 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34261:

Media: Ensure that HTML5 captions apply the 'img_caption_shortcode_width'.

Props joemcgill.
Fixes #31053.

Note: See TracTickets for help on using tickets.