I am using the following filter to remove the inline style in the image tag when used in the content editor of the ACF text field:
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;
}
BUT it seems to remove the caption as well as the surrounding markup. How can I remove the inline image size and retain the caption?
This is the markup that WordPress inserts when an image is placed into the text field:
div id="attachment_210" style="width: 1610px" class="wp-caption
alignnone"
So you can see that the inline style makes the container 1610px, and an image set to 100% would fit the fixed width container. I'm looking for a way to remove the div markup, which the above filter does, but it also removes the caption, which I want to retain