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

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.

Latest from the Lab

What does a website cost in Fort Myers and Naples? Informational $2k to $4k, custom WordPress $4k to $8k, ecommerce $6k to $15k

How Much Does a Website Cost in Fort Myers and Naples?

Real website prices for Southwest Florida small businesses, from $2,000 informational sites to custom
EnterpriseHS.org shown on a desktop browser and a phone

Website Launch: Enterprise High School in Clearwater, FL

The new EnterpriseHS.org answers families’ first questions up front and turns enrolling into four
American Pool Water website shown on a laptop browser and a phone

Making a Splash: A New Brand & Website for American Pool Water

A new logo and website for American Pool Water, a pool water delivery company
blank

Alliant Association Management: New Logo, Brand Identity and Website

A new logo, brand identity and website for Alliant Association Management, an HOA and