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 either of the following to the iframe code:

  • the data-skip-lazy attribute
  • or the skip-lazy class

Examples:

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

These are available from WP Rocket 3.5 and are part of a cooperation between plugin authors of LazyLoad solutions to standardize exclusions. That means if you switch between one of the cooperating plugins and are using one of these exclusion methods, it will still apply in the alternate solution.

If you were previously using data-no-lazy, this will still work for WP Rocket specifically.

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.