Prevent Width and Height Attributes in Image Tag Output

Use wp_get_attachment_image_src() and build a simplified img element. You may use something like the following code as a replacement for wp_get_attachment_image():

function wpse_53524_get_image_tag( $attach_id, $size, $icon, $alt="" )
{
    if ( $src = wp_get_attachment_image_src( $attach_id, $size, $icon ) )
    {
        return "<img src="https://wordpress.stackexchange.com/questions/53524/{$src[0]}" alt="$alt" />";
    }

}

Put the function above into your theme’s functions.php. Call it like wp_get_attachment_image():

foreach ( $attachments as $attachment ) {
    echo wpse_53524_get_image_tag( $attachment->ID, 'full', false );
}

Leave a Comment