Native Lazy Loading

Starting with Chrome 76, you’ll be able to use the new loading attribute to lazy-load resources without the need to write custom lazy-loading code or use a separate JavaScript library.

Pentru a introduce lazy-loading in WordPress trebuie adaugata urmatoarea functie in fisierul functions.php din tema.

function lazy_loading($content) {
    $search = array('<img', '<iframe');
    $replace = array('<img loading="lazy"', '<iframe loading="lazy"');
    $content = str_replace($search, $replace, $content);
    return $content;
add_filter('the_content', 'lazy_loading');

O scurta explicatie a codului: cauta tag-urile <img & <iframe si le da replace cu <img loading="lazy", respectiv <iframe loading="lazy".