WP Rocket’s LazyLoad feature improves website performance by loading YouTube videos only when users interact with them. By default, WP Rocket selects a specific resolution for YouTube thumbnails, but you can change it using a simple snippet. If you are using the Perfmatters plugin for the LazyLoad feature, then you should read this post.
Why Change the YouTube Thumbnail Resolution?
By default, WP Rocket uses a predefined thumbnail resolution. However, in some cases, you may want to adjust it for better quality or faster loading times.
Snippet to Modify YouTube Thumbnail Resolution
To change the resolution of YouTube thumbnails in WP Rocket’s LazyLoad, add the following snippet to your theme’s functions.php
(child theme) file or via Code Snippets plugin. You can change the value in the $thumbnail_resolution = ‘sddefault’ line to increase or decrease the quality of the preview image.
The existing values are:
‘maxresdefault’,
‘sddefault’,
‘mqdefault’,
‘hqdefault’,
‘default’
add_filter( 'rocket_lazyload_youtube_thumbnail_resolution', function( $thumbnail_resolution ) {
//default, mqdefault, sddefault, hqdefault, maxresdefault.
$thumbnail_resolution = 'sddefault';
return $thumbnail_resolution;
} );
Leave a Reply