0

I'm using WordPress' built in gallery feature on a post. However, it produces the images with inline height and width attributes:

<dt class="gallery-icon portrait">
    <a href="http://fashion-detail.dev/?attachment_id=6">
        <img width="150" height="150" src="http://fashion-detail.dev/wp-content/uploads/2014/02/fd-1-150x150.jpg" class="attachment-thumbnail" alt="fd-1">
    </a>
</dt>

And I have tried the following filters, but none work:

add_filter( 'get_image_tag', 'remove_width_and_height_attribute', 10 );
add_filter( 'post_gallery', 'remove_width_and_height_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_and_height_attribute', 10 );

function remove_width_and_height_attribute( $html ) {
   return preg_replace( '/(height|width)="\d*"\s/', "", $html );
}

I am not sure what the image is defined as: a thumbnail, a gallery image? What do I need to filter to remove this?

4
  • Hmm, neither of those solutions seem to be changing the size. I'm not using a shortcode, this is generated from the 'Insert Media' button.
    – tmyie
    Commented Feb 20, 2014 at 12:47
  • Well, does it remove the width and height attributes? If yes - of course they display in the size the images are. Please clarify your question.
    – kraftner
    Commented Feb 20, 2014 at 12:49
  • Okay, it hasn't removed the image attributes, but it is still linking to a thumbnail image that is 150 x 150. I assume I need to remove the inline width and height styles, and ask WordPress to not resize the gallery thumbnail?
    – tmyie
    Commented Feb 20, 2014 at 12:53
  • 1
    @tmyie All galleries use shortcodes, look in the text tab and you'll see the shortcode. You just won't see the shortcode in the visual tab
    – Tom J Nowell
    Commented Feb 20, 2014 at 14:52

0

Browse other questions tagged or ask your own question.