Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /**
  2. * Gets an attachement image as lazy loaded img based on ID
  3. * @param string $size Thumbnail, medium, large, original, or {custom size}
  4. * @param string $class CSS class name for the img tag
  5. * @param integer $attachment_id ID of the attachment
  6. * @param string $attachment_id The custom src atrribute to use, default to data-echo
  7. * @return string Lazyload friendly HTML img tag
  8. */
  9. function get_attachemt_lazy($size, $class, $attachment_id = "", $src_attr = "data-echo")
  10. {
  11. $src = wp_get_attachment_url($attachment_id);
  12. $attr = array(
  13. 'class' => "attachment-$size $class",
  14. 'src' => 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==',
  15. $src_attr => $src,
  16. );
  17. $output = wp_get_attachment_image($attachment_id, $size, false, $attr);
  18. return $output;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement