Remove Width & Height Attributes From Uploaded Images

[ad_1]

If you upload images via the WordPress media uploader and insert it into your post, it will automatically include the image width and height attribute in the html <img> tag. These are normally desirable, as it assists the browser in making the appropriate room for the image during layout.

But for some reason if you want to get rid of these attributes from <img> tag in html, you can add this code to you functions.php file.

// remove image width and height attribute
function wcs_remove_img_attributes( $html ) {
    $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
    return $html;
}
add_filter( 'post_thumbnail_html', 'wcs_remove_img_attributes', 10 );
add_filter( 'image_send_to_editor', 'wcs_remove_img_attributes', 10 );

That’s all you need to do.

[ad_2]

PROMEX · YOUR ACCOUNT

Login / Register

Use your WhatsApp number. We’ll send you a code to sign in securely.

Your code expires in 5 minutes. Never share it with anyone.