According to jQuery.lazyload any images I’d like to “lazyload” need to have the src
attribute replaced with data-original
.
I’m assuming I can do this using WordPress get_image_tag filter, but I’m stuck on how to actually make it happen.
function image_src( $id, $alt, $title, $align, $size ) {
$html = '<img data-orginial="' . esc_attr($img_src) . '"/>';
return $html;
}
add_filter( 'get_image_tag', 'image_src', 10, 5 );
For lazyload to work a lazy
class also needs to be placed on the IMG, which I managed to get working using WordPress get_image_tag_class filter
function image_class( $classes ) {
return $classes . ' lazy';
}
add_filter( 'get_image_tag_class', 'image_class' );
Any thoughts on how I can change the IMG output to replace data-orginial
instead of src
?
Rich-
I ran into the same problem and went down the same path as you, trying to use
get_image_tag
with poor results. So I came up with a JS workaround – the code comments should show you how to get this working:You will need to replace the
src
partYou may have to adjust it to make it match the original
<img>
settings.Edit: added Nath’s suggestion.