[wp-trac] [WordPress Trac] #17044: div.wp-caption shortcode should have width of img, rather than add +10px
WordPress Trac
wp-trac at lists.automattic.com
Mon Apr 4 13:30:48 UTC 2011
#17044: div.wp-caption shortcode should have width of img, rather than add +10px
--------------------------+-----------------------------
Reporter: mgk25 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Shortcodes | Version: 3.1
Severity: normal | Keywords:
--------------------------+-----------------------------
In WordPress 3.1, file wp-includes/media.php function
img_caption_shortcode() ends with the line
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '"
style="width: ' . (10 + (int) $width) . 'px">'
[...]
This line unfortunately hardwires into WordPress (apparently since version
2.6) a style-sheet issue, namely it makes the <div> that combines an image
with its caption text 10 pixels wider that the image itself.
Why, and why exactly 10px?
This seems a bad idea for several reasons:
- The addition of a caption needlessly changes horizontal spacing around a
floating image by 10px, which looks awkward if a posting includes several
left-floating images, some of which have captions and some of which do not
(and therefore use no caption shortcode). Those images that have captions
will have 10px additional space compared to those that do not, leading to
an uneven appearance that can't be fixed neatly in theme CSS.
- Any desired additional space could easily be offered in the theme CSS
via a margin, and there is no need to hardwire this into the width, Such
stylistic choices (such as 10px) should really be left to the theme CSS,
rather than hardwired into WordPress.
Proposed patch:
Please replace in the above line the term
(10 + (int) $width)
with
((int) $width)
in other words remove the hardwired additional width for the img+caption
containing div.
Users have complained about this issue many times in the support forum,
and it clearly causes a lot of confusion and unexpected behaviour, but I
haven't seen it yet filed as a bug:
http://wordpress.org/support/topic/10px-added-to-width-in-image-captions
http://wordpress.org/support/topic/attached-image-captions-adding-10px
http://wordpress.org/support/topic/wp-caption-how-to-set-the-right-and-
left-padding-for-captions
http://wordpress.org/support/topic/control-of-image-caption-width
http://wordpress.org/support/topic/should-i-edit-mediaphp
A related complaint:
http://core.trac.wordpress.org/ticket/9066
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17044>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list