Change WP Rocket lazyload treshold
Author: Aleš Sýkora, 21. 1. 2021
Default treshold for lazyload is 300px in WP-Rocket. That means that images that are within 300px of the viewport (browser window) are loaded for smooth user experience.
If you like to load less images - for example 100px after viewport only - you can not set it up directly in WP Rocket's settings page.
To adjust WP Rocket Lazyload treshold, you need to use this filter:
function rocket_lazyload_custom_threshold( $threshold ) {
return 100;
//height in pixels
}
add_filter( 'rocket_lazyload_threshold', 'rocket_lazyload_custom_threshold' );
Put it in your code snippets, custom funcionality plugin or to functions.php i your child theme.