How to remove height and width attributes from Image Uploader

06 June 2013 - wordpress tips remove height width from image uploader

Every time you upload images into WordPress from the image uploader directly in your post or through the media uploader, it will automatically add the height and width of the image into the html tag.

Most of the time it’s fine that the image tag has the width and height but, if you’re like me and are working with a responsive theme and need to remove it…here are the steps to follow.

Remove height and width attributes from image tag

1. Open your theme’s functions.php file. (Access this file via FTP or through the Dashboard → Appearance →  Editor)

2. Copy and paste the following code:

3. Save the changes.

All done!  Now, when you upload a new image using the WP media uploader, the width and height attribute will no longer be added to the image tag.

Please note: if you are new at this, make sure to backup the file before you change anything. The functions.php file is a highly sensitive file and you want to have a backup just in case something goes wrong!

If you are unsure where to add this code within the functions.php file, the only thing to remember is to be careful not to add it inside another function…it is best to add it at the bottom of the file. If your file does not have a php closing tag that’s fine, just plop the code in and save.

 

Leave a Reply

Your email address will not be published. Required fields are marked *