Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Remove Width and Height Attributes From Images in WordPress

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.

WordPress snippets

How to Remove Width and Height Attributes From Images in WordPress

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.

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.

The post How to Remove Width and Height Attributes From Images in WordPress appeared first on FreeWebMentor.



This post first appeared on Programming Blog Focused On Web Technologies, please read the originial post: here

Share the post

How to Remove Width and Height Attributes From Images in WordPress

×

Subscribe to Programming Blog Focused On Web Technologies

Get updates delivered right to your inbox!

Thank you for your subscription

×