WordPress Snippets at WPcustoms

Remove image dimension attributes

By default WordPress auto adds the images height and width to the img src code as regular html attributes. This is correct but in some cases you may want to change these settings. Those two filers allow you to modify the output with a preg_replace regexpression.


/**
 * Snippet Name: Remove image dimension attributes
 * Snippet URL: http://www.wpcustoms.net/snippets/remove-image-dimension-attributes/
 */
 function wpc_remove_thumbnail_dimensions( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}
add_filter( 'post_thumbnail_html', 'wpc_remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'wpc_remove_thumbnail_dimensions', 10 );