If you want to remove the height value from your img URL, you can use this function:
add_filter( 'post_thumbnail_html', 'remove_thumbnail_height', 10, 5 );
function remove_thumbnail_height( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$html = preg_replace( '/height=\"\d*\"https://wordpress.stackexchange.com/", "", $html );
return $html;
}
This will replace the height with an empty value. Note that you can’t use Auto
as a value for the height
property. It won’t be validated by w3 validator. However, you can set the height to auto in your CSS:
.wp-post-image {
height: auto;
}