Possible Duplicate:
Prevent Width and Height Attributes in Image Tag Output

i would like to remove the width="512" height="128" attributes on an attachments

this method is fine on images displayed in the_content : Filter to remove image dimension attributes?

but i can't find a way to make it work on an attachement i call outside of the_content with wp_get_attachment_image.

how can i do this ?

  • just found the solution ! $myimage = preg_replace( '/(width|height)=\"\d*\"\s/', "", wp_get_attachment_image($first_attachment->ID, full) ); echo $myimage;
    – user9446
    Oct 14, 2011 at 23:10

1 Answer 1


wp_get_attachment_image() does not pass output through any filters. You should apply changes to output of this function or use custom function for output.

  • There's a filter inside wp_get_attachment_image though, named .. wp_get_attachment_image_attributes, perhaps you could catch the size there? Not sure who downvoted this answer, curious to know the reasoning..
    – t31os
    Oct 15, 2011 at 17:01
  • @Mark filtered attributes are additional ones, width and height are retrieved and concatenated separately and do not pass through that filter.
    – Rarst
    Oct 15, 2011 at 17:47