Responsive Web Design Tip: Remove Height & Width from Images in WordPress

Share on facebook
Facebook
Share on twitter
Twitter

Whenever we build a custom WordPress website and need to make it responsive, we remove the height and width from images inserted into the post content so that they’ll play nicely in a responsive layout.

// Remove height/width attributes on images so they can be responsive
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );

function remove_thumbnail_dimensions( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}

This is just one of the many customizations we make to the WordPress system to get it ready for a fully responsive web design experience.

Let's Talk
We can't wait to hear about your project.
  • required
  • required
  • required
  • required
    *Sorry, "Johnny Flyaway" recently retired. We hope an email response or phone call will suffice.
    Spam isn't fun. We promise to only send you emails with helpful marketing & design tips, and life changing information. Ok, maybe the latter is a bit of an exaggeration, but it's possible!
  • This field is for validation purposes and should be left unchanged.
Web & Logo Design Blog

© 2021 Brian Joseph Studios LLC. All rights reserved

Facebook | Twitter | Instagram | Web Design Naples | Web Design Fort Myers | Logo Design Fort Myers | Logo Design Naples | LinkedIn

Fort Myers - (239) 989 3306 | Naples - (239) 280-1294

Google Business Listing - Brian Joseph Studios - Naples Web Design Company