Learn How to add loading=”lazy” to your images and iframe codes in the pages of your website
Step One | Step Two | Step Tree | Step Four | Step Five
Step 1: Go Trough your Template Folder and find your active template folder Step 2: Open the functions.php file with some code editor like Atom, Notepad, etc. Step 3: At the top of the file right after the opening <?php tag add the snippet below to register and add template support for your custom WordPress Template with the default WordPress Lazy Load Function since WordPress 5.5 Version Announce
// Enable WordPress Default Lazy Load Functions for Images, Videos, Iframes add_theme_support( ‘lazy-load’ );Step 4: To get this work after adding this snippet above ^^ to your functions.php save the file to your server and viola your WordPress Template Support Lazy Loading Images and Lazy Loading I frames without adding Lazy Load Plugin or Other Additional Scripts to your WordPress Template files Step 5: go Trough your Templates With Loops and <img src element and add before the closing img tag loading=”lazy” and your images from the loops or queried post or pages will load lazy
Example of image version with lazy load value-added below
<img src=”URL to your image” title=”The image title” alt=”the alternative image text” width=”640″ height=”480″ loading=”lazy”/>
Lazy Load Function to Disable the Default WordPress Functionality for Lazy LoadCopy and Paste the Lazy Load Disable snippet into your Custom WordPress theme functions.php file. Save the Lazy Load Snippet Code go to Your Page and see how your Images and Videos in Iframe are without the Core Functionality for Lazy Load Function from WordPress.
/* Disable WordPress default image lazy load */ add_filter( ‘lazy-load_enabled’, ‘__return_false’ );