Support » Theme: GeneratePress » implementing html attribute loading=”lazy on all images by default”

  • Resolved michaelgof

    (@michaelgof)


    Hi tom

    i can across this tweet which shows how the mentioned website cut down their total page load for one of their pages by ~90%

    after doing some searching, i can across this code snippet on css tricks of how they implemented it on their site.

    <?php
        function csstricks_add_lazy_loading($content)
        {
         $content = preg_replace('/src="/', '
         	loading="lazy" src="', $content);
          return $content;
    
        }
        add_filter ('the_content', '
        	csstricks_add_lazy_loading');
    
    ?>

    essentially the code searches for any HTML that contains a src=”” and filtering it to also include loading=”lazy” attribute

    is there a way i can edit this code or may be create something similar to include in generatepress?

    i’d like to test this too on the child theme.

    may be something you could consider implementing in future versions of generatepress

    • This topic was modified 7 months, 2 weeks ago by michaelgof.
    • This topic was modified 7 months, 2 weeks ago by michaelgof.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘implementing html attribute loading=”lazy on all images by default”’ is closed to new replies.