4

Displaying Vimeo Thumbnails In Your Blog Post or Archive

With WordPress 2.9, you can now embed videos by simply pasting the URL into your blog post and have it create the embed code. I was using Vimeo and wanted to pull the thumbnail associated with the Vimeo video which was embedded in my posts.

Here’s how:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
global $wp_query;
$postid = $wp_query->post->ID;
$sourcestring = get_the_content($postid);
preg_match('/http://vimeo.com/(d+)$/', $sourcestring, $matches);
if (count($matches) != 0)
{
$vimeo_id = $matches[1];
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vimeo_id.php"));
?>
<img src="<?php echo $hash[0]['thumbnail_large']; ?>" alt="" />
<?php
}
?>

You can get the thumbnails in 3 different sizes: small, medium and large.

Small

1
<img src="<?php echo $hash[0]['thumbnail_small']; ?>" alt="" />

Medium

1
<img src="<?php echo $hash[0]['thumbnail_medium']; ?>" alt="" />

Large

1
<img src="<?php echo $hash[0]['thumbnail_large']; ?>" alt="" />

I’ll probably get around to writing a function for it later.

Thanks to Eugene Gimelberg for the tip!

Comments (4)

  1. Adrian says:

    Thanks for doing this guide! It’s just what I need for a project.

  2. David says:

    I used this great function for a while, but file_get_contents isn’t enabled for security reasons on many accounts. So I rebuilt this functionality using cURL here: http://www.soapboxdave.com/2010/04/getting-the-vimeo-thumbnail/

  3. Tri Vuong says:

    Do you know if there is any hard limit on the number of calls you can make to Vimeo? Thanks.

  4. harsha says:

    Thanks a lot.

    This is what i required for my project.

Leave a Reply