I have many images on site and can't edit them individually so I want to edit them on a global scale so that they all benefit from this code https://github.com/aFarkas/lazysizes
I have viewed this video but his demonstration is on a per image basis from what I can tell https://www.youtube.com/watch?v=Uwnmn65cMec
Am I correct in assuming the src for that plugin goes in the footer.php like this:
<script src="https://unpkg.com/lazysizes@4.0.1/lazysizes.js"></noscript>
and then it is a case of adding some code somewhere else to edit/add a class to every image and edit the src of every image so that it says data-src?
I am far from a coder, and not sure how to put that together. I saw this for inputting the image class but it's to make images responsive and doesn't tell me how to edit the src as well.
function add_responsive_class($content){
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML(utf8_decode($content));
$imgs = $document->getElementsByTagName('img');
foreach ($imgs as $img) {
$img->setAttribute('class','img-responsive');
}
$html = $document->saveHTML();
return $html;
}
Where I found that code: How to add automatic class in image for wordpress post
Thanks