[wp-trac] [WordPress Trac] #43123: Default captions should NOT use max-width

WordPress Trac noreply at wordpress.org
Fri Mar 2 22:55:35 UTC 2018


#43123: Default captions should NOT use max-width
--------------------------+------------------------------
 Reporter:  smerriman     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  4.9
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by jakeqz):

 I've also found this issue and would like to add my voice to those calling
 for #33981 to be reverted.  Just updated to WordPress 4.9 and found images
 squashed 10px narrower in some themes (which were ultimately based on
 TwentyTwelve).  #33981 was the culprit.  Another issue introduced is that
 a second floated image will (at least in Firefox) be shrunk to fit into
 the space beside the first, where it should not fit at its intrinsic size.

 The change in #33981 breaks themes and has no justification given – no use
 case example was provided demonstrating why this change was required, only
 that it was to be "more mobile friendly".  However, it is much more common
 in RD to use `max-width: 100%` in the CSS to constrain images to the
 available space, and set specific optimal image widths as inline styles
 using the `width` property (NOT `max-width`!) or via the `width` attribute
 – could the issue that #33981 was attempting to address not have been
 solved like this?

 I suggest that a filter is added for `$style` with the default behaviour
 reverted to that in 4.8, so that existing themes are not broken and anyone
 who really needs `max-width` instead of `width` can do so be adding a
 filter, something like this in `image_caption_shortcode`:

 {{{
 $style = '';
 if ( $caption_width ) {
     $style = 'style="width: ' . (int) $caption_width . 'px" ';
 }
 $style = apply_filters( 'img_caption_shortcode_style', $style, $atts,
 $content, $caption_width, $html5 );
 }}}

 Currently it is possible to partially revert #33981 by adding a filter,
 but this is clumsy as it requires adding the filter for every single
 shortcode and (the example below) assumes no other element in the content
 will have a `max-width` style, and it does not cover other uses of
 `img_caption_shortcode` such as by the Media Image widget.  No other more
 suitable filter is currently available:

 {{{
 add_filter(
     'do_shortcode_tag',
     function( $output, $tag, $attr, $m ) {
         if ( $tag === 'wp_caption' || $tag === 'caption' ) {
             $output = str_replace( 'style="max-width:', 'style="width:',
 $output );
         }
         return $output;
     },
     10, 4
 );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43123#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list