Remove Width/Height from Images

For making images inside posts mobile responsive:

$ function() {
     $ (".post img) .removeAttr("width") .removeAttribute("height");
}

 Or, within your functions.php:

add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );

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

 

Comments are closed.

Skip to toolbar