WordPress.org

Ready to get started?Download WordPress

Ideas

Insert image size attributes into img tags in posts

  1. satchel
    Member

    12345

    There have been a lot of suggestions about expanding the image capabilities of WordPress. This proposal is for something much simpler, which wouldn't interfere with those proposals. (It could be implemented whether the others are added or not) It merely would allow 90% of WordPress pages to load much more smoothly.

    How? Typically, images in WordPress are not given width and height specifications within the img tag. I do this myself as a matter of course, for every post, and it's a pain, because I have to do it manually. First, I have to look up the image size in Photoshop or in the Windows Explorer. Then, I have to go into the Code tab and manually enter the width and height attributes into the img tag.

    Why do I do this? Because browsers rely on width and height attributes to lay out pages quickly. When a big image is loading slowly, if a width and height are provided, the rest of the page can render and the browser doesn't have to wait for the image to load in order to see how big the image will be.

    So here are two simple proposals, either of which could be implemented (though I'd prefer both):

    One is simply to have WordPress's image editor indicate the native size of an image when it is displayed within the image browser, and maybe to have the height and width automatically placed in an alterable field, so the image can be resized if that is desired (I would never do that within WordPress, because I trust Photoshop's resizing algorithms much more, but others may want to).

    The other is simply to have WordPress automatically add width and height attributes to img tags as they are inserted into the post's code when an image is added to a post. These would either come from the native size of the image or thumbnail, or --- if the previous suggestion is implemented --- from the field in the image browser.

    Both proposals could be options, selectable in the options menu.

    Posted: 7 years ago #
  2. jabecker
    Member

    12345

    The automatic add of width/height attributes should include the ability to add only one of the attributes (i.e. only width or only height), and should be customizable to allow for a "default" width and/or height.

    I modified upload-js.php so that a default width is added to an img tag. I add width only so that I don't have to mess with the aspect ratio. The default works for about 90% of images that I post.

    It would be cool not to have to make that change after every WP upgrade.

    Posted: 7 years ago #
  3. niki
    Member

    I set


    .entry img {
    display: block;
    }

    in my css.

    (works for me because typically my images are full width so I don't need to wrap text around them. inline-block might be a workable alternative?)

    Posted: 6 years ago #
  4. cet
    Member

    .entry img {
    display: block;
    }

    Posted: 4 years ago #
  5. External HDD
    Member

    I think that this might be great and it will give use wordpress users great chance to enhance our posts.

    Posted: 4 years ago #
  6. Chip Bennett
    Theme Review Admin

    It appears that the default settings for the Insert Image tool in the post editor add the height and width attributes to images.

    I think this one can be closed.

    Posted: 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    12345
    2 Votes
  • Status

    This idea has been implemented