Published on Apr 21, 2020
How to get Thumbnail URL and other info from a Vimeo ID in WordPress
Sridhar Katakam
If you are looking to get thumbnail URL or other data like the video title from the video ID for public videos on Vimeo in your WordPress site, here’s a handy function that uses Vimeo’s oEmbed endpoints:
/**
* Grab the specified data like Thumbnail URL of a publicly embeddable video hosted on Vimeo.
*
* @param str $video_id The ID of a Vimeo video.
* @param str $data Video data to be fetched
* @return str The specified data
*/
function get_vimeo_data_from_id( $video_id, $data ) {
$request = wp_remote_get( 'https://vimeo.com/api/oembed.json?url=https://vimeo.com/' . $video_id );
$response = wp_remote_retrieve_body( $request );
$video_array = json_decode( $response, true );
return $video_array[$data];
}
Sample usage:
<?php
echo get_vimeo_data_from_id( '158115405', 'thumbnail_url' );
?>
output:
https://i.vimeocdn.com/video/559534542_640.jpg
Available data:
If you want to see the contents of the array, you could
echo '<pre>';
print_r( $video_array );
echo '</pre>';
after
$video_array = json_decode( $response, true );
References
https://www.briancoords.com/tech/get-thumbnail-vimeo-api/
https://wordpress.stackexchange.com/a/115910/14380
https://developer.wordpress.org/reference/functions/json_decode/#comment-3769