[Support request] Caption sizing problem

Home Forums Support [Support request] Caption sizing problem

Home Forums Support Caption sizing problem

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #288145
    Dave Foy

    I’ve discovered an odd issue with the HTML generated by image captions. I don’t know if this is a GP issue or not?

    I add an image to a blog post. I type a caption.

    The resulting caption shortcode in my post looks like this (simplified):

    [caption width="395"]<img src="" alt="" width="395" height="115" /> Caption text[/caption]

    That’s great so far, and as expected.

    However: in the HTML output on the front end, the width attribute of the <figure> element is 10px less than the image.

    Example:

    <figure style="width: 385px" ><img src="" alt="Page builder integeration settings panel" width="395" height="115"><figcaption>Caption text</figcaption></figure>

    Notice the width in the style attribute of the figure element is 10px less than the width attribute on the image itself.

    So this in effect makes my image 10px smaller than it should be (in the above example, the image is displaying at 385px wide).

    The problem here is that because the image is being scaled a little, it looks less crisp and sharp than when it’s at it’s full intended width. It’s the reason I noticed the issue in the first place.

    I fixed it by manually editing the width in the caption shortcode, by adding 10px to it.

    Example:

    [caption width="405"]<img src="" alt="" width="395" height="115" /> Caption text[/caption]

    This worked great – the figure width was output at 395px on the site (10px less than in the caption shortcode), so all was well. A hack, but fine. πŸ™‚

    However, I’ve since checked again (while looking back at the original post for examples for this support request), and the width values on my captions have all reverted back to what they were before I manually edited them. So now back to square one.

    Hmmm.

    Do you have any ideas?

    Thanks for your help.

    #288148
    Dave Foy

    Actually, I don’t know if the width values reverted back (see my last paragraph) – there’s a chance I just didn’t manually update all of them in the end.

    The actual main issue remains though. πŸ™‚

    #288299
    Tom
    Lead Developer
    Lead Developer

    Hmm, I know that WP used to add 10px of width to the caption area which I had to remove. I wonder if they’ve changed that.

    Try this function:

    add_action( 'after_setup_theme','tu_regulate_caption_width' );
    function tu_regulate_caption_width() {
        remove_filter( 'img_caption_shortcode_width', 'generate_remove_caption_padding' );
    }
    #288303
    Dave Foy

    Yes that works. πŸ™‚

    I guess WP must have changed things then?

    Many thanks Tom. Appreciated.

    #288317
    Tom
    Lead Developer
    Lead Developer

    I’ll investigate πŸ™‚

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.