Hi,
Is there a possibility to change the default YouTube API preview image quality? Something like WP Rocket has: Choose YouTube preview image resolution - WP Rocket Knowledge Base
Thanks
Hi,
Is there a possibility to change the default YouTube API preview image quality? Something like WP Rocket has: Choose YouTube preview image resolution - WP Rocket Knowledge Base
Thanks
UPDATE
Iāve checked the video element code and here is the part used for chosing the video thumbnail:
// STEP: Get YouTube video preview image from API
if ( $video_type === 'youtube' ) {
return "https://img.youtube.com/vi/{$settings['youTubeId']}/hqdefault.jpg";
}
So, there is no way to change the thumbnail quality except editing the code directly.
It would be really handy to add there a possibility to change the quality. At least via filter, ideally in UI.
The simple filter could look something like this:
// STEP: Get YouTube video preview image from API
if ( $video_type === 'youtube' ) {
$thumbnail_resolution = apply_filters( 'bricks/youtube_thumbnail_resolution', 'hqdefault' );
return "https://img.youtube.com/vi/{$settings['youTubeId']}/{$thumbnail_resolution}.jpg";
}
And yes, Iām aware this could lead to possible issues, since some of the resolutions might not be available. If using the UI, there should be some info about it there.
Iām making this a feature request now. Thanks for considering itā¦
My client was very unhappy when the Preview image by Default API is completely pixelated in full width container⦠Bricks uses a 480x360 hqdefault resolution, which is good for mobile devices, but definitely not for desktops. For 1280x720, you just need to change: return āhttps://img.youtube.com/vi/{$settings[āyouTubeIdā]}/hqdefault.jpgā;
in to:
return āhttps://img.youtube.com/vi/{$settings[āyouTubeIdā]}/maxresdefault.jpgā;
@thomas @Matej I think itās not too hard to provide a filter or option?
My solution, but I need confirmation if this is a good approach?:
/**
function replace_youtube_thumbnail_quality( $content, $post, $area ) {
// Only process if content contains YouTube thumbnails
if ( strpos( $content, āimg.youtube.com/vi/ā ) === false ) {
return $content;
}
// Replace hqdefault.jpg with maxresdefault.jpg
$content = str_replace(
'/hqdefault.jpg',
'/maxresdefault.jpg',
$content
);
return $content;
}
Hi @drigis3,
I have not testes your workaround, but if itās working, I donāt see any other problem.
Also, Iāve created an internal improvement task for this and linked this topic to it.
Thank you,
Matej
We added this imrpovement in Bricks 2.1.3, now available as a one-click update in your WordPress Dashboard.
Please take your time to read the changelog entry before updating, and let us know if you continue to experience issues.