I'm a bit lost here. I'm trying to replace src
tag with data:image/gif;base64,R0lGODlhAQABAPABAAAAAP///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
for lazy loading and add class lazyload
so lazysizes could work. But none of that is successful here.
Am I missing something?
public static function filter_lazy_load_gravatar( $html ) {
$html = preg_replace( '/src="(http:\/\/([^\/]+)\/)?([^"]+)"/', 'src="data:image/gif;base64,R0lGODlhAQABAPABAAAAAP///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="', $html);
$html = str_replace( 'srcset=', 'data-srcset=', $html );
$pat = '/class="([^"]*)"/';
$html = preg_replace($pat, 'class="$1 lazyload"', $html);
return $html;
}
Input
<img alt="" src="http://gravatar.com/image.jpg" srcset="http://0.gravatar.com/avatar/0b11f7eec98d2ee78414a4322ea94a01?s=400&d=mm&r=g 2x" class="avatar avatar-200 photo" height="200" width="200">
Expected output
<img alt="" src="data:image/gif;base64,R0lGODlhAQABAPABAAAAAP///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-srcset="http://0.gravatar.com/avatar/0b11f7eec98d2ee78414a4322ea94a01?s=400&d=mm&r=g 2x" class="avatar avatar-200 photo lazyload" height="200" width="200">