Updates, Tips & Tricks

Updates as Released, Plus My Personal Collection Of WordPress Best Practices

Remove Pesky Width and Height on WordPress Images Using a Filter

25 March

Not the best way to go about it perhaps, but it works. Add the following filter to functions.php:

// Remove the automatic width and height on images added by WordPress
function remove_thumbnail_dimensions( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 5 );
No comments yet.

Leave a Reply