The Image Widget includes width
and height
on the images which I've unsuccessfully have been trying to filter out so I can have fluid width.
I've tried the following, which seems to be the most common solutions for similar problems, in functions.php
, but without success:
function responsive_image_widget( $attr = array() ) {
unset($attr['width']);
unset($attr['height']);
return $attr;
}
add_filter( 'image_widget_image_attributes', 'responsive_image_widget' );
and
function responsive_image_widget($html) {
$html = preg_replace('/(width|height)=["\']\d*["\']\s?/', "", $html);
return $html;
}
add_filter('image_widget_image_attributes','responsive_image_widget', 10);
Here is a link for the Image Widget's filter documentation.
Any help is much appreciated!