title: Add attribute to wp_get_attachment_image
body: <p>I'm trying to add an attribute to the result of <code>wp_get_attachment_image</code>.</p>
  <p>I want to use jquery lazyload to handle loading of my post thumbnails and to do that I need to add a <code>data-original=</code> attribute to the <code>&lt;img&gt;</code> tag <code>wp_get_attachment_image</code> is creating.</p>
  <p>I've tried:</p>
  <pre><code>$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), &quot;full&quot; );
  $imgsrc = $imgsrc[0];
  $placeholderimg = wp_get_attachment_image( 2897, &quot;full&quot;, array('data-original'=&gt;$imgsrc) );
  </code></pre>
  <p>But it doesn't add the data attribute as I expected.</p>
  <pre><code>&lt;img class=&quot;attachment-full&quot; width=&quot;759&quot; height=&quot;278&quot; alt=&quot;...&quot; src=&quot;...&quot;&gt;&lt;/img&gt;
  </code></pre>
  <p>Looking at the <code>wp_get_attachment_image</code> function it would seem that this ought to work though:</p>
  <pre><code>function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
       
   
      $html = '';
   
      $image = wp_get_attachment_image_src($attachment_id, $size, $icon);
   
      if ( $image ) {
   
          list($src, $width, $height) = $image;
   
          $hwstring = image_hwstring($width, $height);
   
          if ( is_array($size) )
   
              $size = join('x', $size);
   
          $attachment =&amp; get_post($attachment_id);
   
          $default_attr = array(
   
              'src'   =&gt; $src,
   
              'class' =&gt; &quot;attachment-$size&quot;,
   
              'alt'   =&gt; trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
   
              'title' =&gt; trim(strip_tags( $attachment-&gt;post_title )),
   
          );
   
          if ( empty($default_attr['alt']) )
   
              $default_attr['alt'] = trim(strip_tags( $attachment-&gt;post_excerpt )); // If not, Use the Caption
   
          if ( empty($default_attr['alt']) )
   
              $default_attr['alt'] = trim(strip_tags( $attachment-&gt;post_title )); // Finally, use the title
   
   
   
          $attr = wp_parse_args($attr, $default_attr);
   
          $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
   
          $attr = array_map( 'esc_attr', $attr );
   
          $html = rtrim(&quot;&lt;img $hwstring&quot;);
   
          foreach ( $attr as $name =&gt; $value ) {
   
              $html .= &quot; $name=&quot; . '&quot;' . $value . '&quot;';
   
          }
   
          $html .= ' /&gt;';
   
      }
   
   
   
      return $html;
   
  }
  </code></pre>
  <p>Where am I going wrong?</p>
  <p>[update] Sometimes it just takes a fresh pair of eyes to spot the idiocy... Thanks to hobo I realised I simply missed out a parameter in my function call :D :P</p>