Skip to Content


Lazy-load iframes below the fold to optimize page load time.

PHP March 15, 2018


nebula()->lazy_iframe($src, $attributes)


(Required) (String) The path to the iframe
Default: None

(Optional) (String) Any additional attributes to add to the img tag
Default: None

Parameter Notes

The $attributes tag is simply a string of any additional attribute tags to add. See examples below.

Request or provide clarification »


Lazy load an iframe with only a path

<?php nebula()->lazy_iframe('//'); ?>

Lazy load an iframe with additional attributes

<?php nebula()->lazy_img('//', 'class="cool-iframe" title="Pinckney Hugo Group"'); ?>


Large image loaded normally (not lazy-loaded).

This should appear in a Lighthouse audit under Performance > Opportunities > Offscreen images > View Details

Large image loaded using lazy-load.

Despite being very similar to the previous large image, it will not appear in the same Lighthouse audit.

Lazy loading a background image with the .lazy-load class

This should also not appear in the same Lighthouse audit as above.

Iframe loaded using lazy_iframe().

Additional Notes

This is a convenient alias of lazy_load().

Note: this function does not need to use echo as it prints immediately.

This uses JavaScript to load iframes after the page has finished loading. Any iframes above the fold will be loaded immediately and any below the fold will wait for the user to scroll. These iframes are loaded in <noscript> tags so if JavaScript is not available, the iframes will load as normal (including extra attributes).

A positioning element is added so the offset top can be detected (since <noscript>) tags do not have positioning. This element is removed after it is no longer needed.

Source File

Located in /libs/Optimization.php on line 851.

No Hooks

This function does not have any filters or actions available. Request one?
        public function lazy_iframe($src=false, $attributes=''){
            $this->lazy_load('<iframe src="' . $src . '" ' . $attributes . ' loading="lazy"></iframe>');


This function can not be short-circuited with an override filter. Request one?