IE7\8 compatibility - "px" attribute on images height\width

  1. gerald@WPcustoms



    there is a minor bug in the image_hwstring function which took me quite some time to nail down.
    I tested a theme in IE7 and IE8 browsers where images are floated with css + some responsive css rules.

    those old IE browsers having massive problems when the image height+width attribute is missing "px".
    WordPress renders:
    height="100" width="200"
    source here:

    IE requires:
    height="100px" width="200px"
    google, chrome, safari can handle it easily if PX is missing but as you know IE is always a pain...

    To make a long story short:
    We came up with this solution and jumped into the get_image_tag function

    function custom_dimensions($html, $id, $alt, $title, $align, $size){
        $html = preg_replace('%(width|height)(="[0-9]{1,4})(")%', '$1$2px$3', $html);
        return $html;
    add_filter('get_image_tag', 'custom_dimensions',1, 6);

    so my suggestion: please adjust the image_hwstring function and add the px to save a lot of headaches.

    looking forward to hearing your opinions on this.
    Thank you

    Posted: 6 years ago #
  2. Pat Hawks


    According to the HTML spec, height and width are non-negative integers that define the dimensions of the image in CSS pixels.

    Filling those attributs with anything other than a non-negative integer breaks compatibility with HTML. This seems a pretty price to pay just to make things a bit easier for out dated browsers.


    Posted: 6 years ago #
  3. IE 7 and 8 aren't outdated. Yet. 6, yes, but 7 and 8 are in use a lot.

    Still this looks like a legit IE bug, so if you want to post it on trac, that would be good :)

    Posted: 6 years ago #
  4. Zero_Alpha

    I am having this problem too. A lot of large corporates are using IE8 or older which means many of the images on my site aren't been resized and displayed properly since those browsers don't seem to deal with css very well (or at all).

    These organisations have a lot of our user audience working for them, and it is well beyond our control or our users to change what version of IE their IT departments operate.

    Is there anything I can add to image tags to make sure they are properly sized by older browsers?

    Posted: 5 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    6 Votes
  • Status

    This idea is under consideration