Disable LazyLoad for Iframes

In this Article

Disable LazyLoad on Specific Iframes

There are 2 methods you can choose from to disable Lazyload on specific iframes. 

1. If you can modify the iframe markup directly, add data-no-lazy="1" to the iframe code, eg.

<iframe data-no-lazy="1" width="560" height="315" src="https://www.youtube.com/embed/Srq1FqFPwj0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"  allowfullscreen=""></iframe>

2. If you cannot modify the iframe code directly you may use a filter instead: rocket_lazyload_iframe_excluded_patterns

This will match any part of the iframe code, so simply choose a specific string (i.e a word) from the code to exclude with, such as the domain name or the value of any attribute in the code. Using the iframe code above as an example, you could exclude by the domain: 

function rocket_lazyload_exclude_pattern( $pattern ) {
    $pattern[] = 'youtube';
    return $pattern;
}
add_filter( 'rocket_lazyload_iframe_excluded_patterns', 'rocket_lazyload_exclude_pattern' );

This would exclude all iframes with the text "youtube" in the code.

To be even more specific you could use instead the video ID taken from its URL.

function rocket_lazyload_exclude_pattern( $pattern ) {
    $pattern[] = 'Srq1FqFPwj0';
    return $pattern;
}
add_filter( 'rocket_lazyload_iframe_excluded_patterns', 'rocket_lazyload_exclude_pattern' );

Add the code snippet to the functions.php of your child theme, to your own custom functionality plugin, or use a plugin like My Custom Functions.

Disable Iframe LazyLoad on Specific Pages

Follow the guide here to disable this option on particular pages.

Programmatically Disable Iframe LazyLoad

To programmatically disable iframe lazyload on certain types of pages you may use this filter:
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
For example, to disable LazyLoad on only WooCommerce single product pages you could use the following snippet:
function rocket_lazyload_deactivate_on_single_product() {
	if ( is_singular( 'product' ) ) {
		add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
	}
}
add_filter( 'wp', 'rocket_lazyload_deactivate_on_single_product' );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.