Control of image caption width (7 posts)

  1. Rafael Fischmann
    Posted 8 years ago #

    Dear WordPress staff,

    I really like WordPress 2.6's image caption feature, but it doesn't respect my maximum width for images, which is set to 530 pixels in my functions.php file. Whenever I upload an image, if I use the medium size it's just fine, 530px max. However, if I ask it add a caption below, it adds 10 pixels more, going to 540 pixels. I don't want that.

    Can you fix it, please?

  2. Sherwin Techico
    Posted 7 years ago #


  3. Joshuwar
    Posted 7 years ago #

    If you don't mind poking around in the php, you can change this width- I had the same problem and found the culprit at line 375 of media.php:

    return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'

    Just change '10' to whatever pixel width addition you require. None, in my case.

    This should really be configurable in the editor, though, I agree.


  4. garbokaas
    Posted 7 years ago #

    I totaly agree that the addition of this style-rule is agaist all good practices of seperating form and content.

    Let's hope its a bug that will be removed from media.php soon.

    For now, I deleted the entire style-rule from the php-code. Now I hope I'll remember to check on media.php everytime I upgrade WP.

  5. midstatelitho
    Posted 7 years ago #

    I'm not seeing the entry in media.php that adds the 10px. Perhaps I'm missing something. I'm using wordpress 2.6.3

  6. joelhardi
    Posted 7 years ago #

    I just found this and am also annoyed. The thing I'd point out is that, for floated elements, it's a requirement of the CSS2 spec that an explicit width be specified, so WordPress is doing the right thing by specifying a width. However, hardcoding the extra 10px being added on deep in the application is totally braindead!

    I would definitely mark this as a bug until it's removed. Here's a patch to fix it:

    --- media-old.php       2008-11-21 18:01:11.000000000 -0800
    +++ media.php   2008-11-21 18:01:38.000000000 -0800
    @@ -372,7 +372,7 @@
            if ( $id ) $id = 'id="' . $id . '" ';
    -       return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'
    +       return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (int) $width . 'px">'
            . $content . '<p class="wp-caption-text">' . $caption . '</p></div>';

    I wrote a little bit more about the CSS requirement on this bug report:


  7. jpadie
    Posted 7 years ago #

    and here's a plugin that will do this without a core hack.

Topic Closed

This topic has been closed to new replies.

About this Topic