Opened 7 years ago
Closed 7 years ago
#43185 closed defect (bug) (duplicate)
max-width is causing issue with caption and narrow layouts
Reported by: | brunochartier | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9 |
Component: | Media | Keywords: | has-patch |
Focuses: | ui | Cc: |
Description (last modified by )
wp-includes/media.php was modified in 4.9 (see #33981). This results in messing up caption which are pushed to the right when using narrow window. Since the change is on element, not CSS, this is impossible to overwrite with CSS.
Github commit: https://github.com/WordPress/WordPress/commit/760f9fd3fd743a1de8dd46e61018b232bf38420a#diff-297bf46a572d5f80513d3fed476cd2a2
@@ -1578,7 +1578,7 @@ function img_caption_shortcode( $attr, $content = null ) { $style = ''; if ( $caption_width ) { - $style = 'style="width: ' . (int) $caption_width . 'px" '; + $style = 'style="max-width: ' . (int) $caption_width . 'px" '; } if ( $html5 ) {
After 4.9.1 and changes to media.php:
I understand it has to use the shortcode caption width param so using CSS is complicated. Suggestion: please consider changing the caption width filter to a "style" filter so that is can be overwritten by the theme? ex:
diff --git a/wp-includes/media.php b/wp-includes/media.php index e465e09..a2c6692 100755 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1578,8 +1578,20 @@ function img_caption_shortcode( $attr, $content = null ) { $style = ''; if ( $caption_width ) { $style = 'style="max-width: ' . (int) $caption_width . 'px" '; } + /** + * Filters the style of an image's caption. + * + * @see img_caption_shortcode() + * + * @param string $style the default style attribute + * @param int $width Width of the caption in pixels. To remove this inline style, + * return zero. + * @param array $atts Attributes of the caption shortcode. + * @param string $content The image element, possibly wrapped in a hyperlink. + */ + $style = apply_filters( 'img_caption_shortcode_style', $style, $width, $atts, $content ); if ( $html5 ) { $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
Thanks,
Bruno
Attachments (1)
Change History (5)
#1
@
7 years ago
- Component changed from Shortcodes to Media
- Description modified (diff)
- Summary changed from #42700 is causing issue with caption and narrow layouts to max-width is causing issue with caption and narrow layouts
- Version changed from 4.9.1 to 4.9
Note: See
TracTickets for help on using
tickets.
Related: #42700