In this tutorial, I will explain how to remove width and height attributes from inserted images in WordPress posts and pages. The images uploaded through the WordPress media uploader and inserted in your posts or pages it automatically added the width and height attributes in your image.
If you want to remove the width and height attributes from your images, then use the below code snippets at the end of the functions.php file. The functions.php file is located at wp-content/themes/your-theme-folder/functions.php.
1 2 3 4 5 6 7 8 9 10 | add_filter( 'post_thumbnail_html', 'remove_image_width_attribute', 10 ); add_filter( 'image_send_to_editor', 'remove_image_width_attribute', 10 ); function remove_image_width_attribute( $html ) { $html = preg_replace( '/(width|height)="\d*"\s/', "", $html ); return $html; } |
Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: wordpress image uploader, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners, wordpress upload image