Last active
December 26, 2016 07:40
-
-
Save nucab/70e9b1a1ba751d19574f8554ebc92262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets an attachement image as lazy loaded img based on ID | |
* @param string $size Thumbnail, medium, large, original, or {custom size} | |
* @param string $class CSS class name for the img tag | |
* @param integer $attachment_id ID of the attachment | |
* @param string $attachment_id The custom src atrribute to use, default to data-echo | |
* @return string Lazyload friendly HTML img tag | |
*/ | |
function get_attachemt_lazy($attachment_id = "", $size, $class, $src_attr = "data-echo") | |
{ | |
$src = wp_get_attachment_url($attachment_id); | |
$attr = array( | |
'class' => "attachment-$size $class", | |
'src' => 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==', | |
$src_attr => $src, | |
); | |
$output = wp_get_attachment_image($attachment_id, $size, false, $attr); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment