How to stop image from hardcoding img width and height?

How to stop image from hardcoding img width and height?

You can use the post_thumbnail_html filter to remove the attribute: It’s not the cleanest solution, but it solves your problem. This allows responsive images to work as they should, meanwhile you maintain the width and height attributes in the img element, which is probably better for older browsers, performance and/or to pass HTML validators.

How to remove width and height from images?

You can remove the width and height attributes by filtering the output of image_downsize function found at wp-includes/media.php. To do this, you write your own function and execute it via your theme’s functions.php file or as a plugin. Remove the width and height attributes.

Is it still relevant to specify width and heigth attribute on?

It is, therefore, a good idea to specify the size of the image so that the browser can render the rest of the text on the page while leaving the right amount of space for the image that is still loading. Hence, specifying width and height attribute on image will improve the webpage performance by protecting from delay in loading.

How to set image width and height in CSS?

// the desired width and height (also defined in CSS) You should display width/height as the size in pixels on the screen. If height and width are set, the space required for the image is reserved when the page is loaded.

How to remove image size attributes in WordPress?

If you are working on a non-WordPress project, this solution will work as long as jQuery is loaded. If you aren’t the coding type, or prefer to use a plugin and not add the code to your project, just install the Image Size Attributes Remover plugin.

How to make WordPress images responsive to CSS?

WordPress, by default, will add the width and height attributes to image elements. These attributes will override CSS width and height properties. Making images with these dimension attributes responsive is a bit of a hassle, or in some cases cannot be done at all.