Extracting Youtube Thumbnail Images Dynamically from a Custom Post Type in Worpdress

Posted by Baz Jobson


I’m building a portfolio plugin for a Video Director. The client wants to simply add a YouTube URL to a ‘New Project’ with a ‘Portfolio’ Custom Post Type in WordPress.

I wanted it to automatically extract the thumbnail image associated with that YouTube video directly from YouTube.

The Solution

  1. Query your post type meta.
  2. Extract the YouTube ID
  3. Pass it to $id
  4. Echo the ID (and a width and height variable) to an img src
  5. Voila!

query_posts( array( 'posts_per_page' => 3, 'post_type' => 'project','orderby' => 'ASC',) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
//retrieve the URL from the project post meta
global $wp_query;
$postid = $wp_query->post->ID;
$url = get_post_meta( $postid, '_wpb_video_embed', true );
//extract the youtube ID
//pass the youtube ID to $id
$id = $matches[1];
//set a custom width and height
$width = '365';
$height = '220';
//echo the embed code.
echo '< img class="responsive" src="//img.youtube.com/vi/'.$id.'/0.jpg" alt="" width="' .$width. '" height="'.$height.'" />';


  • Clan Media

    Clan Media | Logo DesignWebsite DesignWordpress Development
    View Website
  • Super 16 Films

    Super 16 Films | Logo DesignWebsite DesignWordpress Development
    View Website
  • Ego Performance Website

    Ego Performance | Website DesignWordpress DevelopmentWordpress Plugin Creation
    View Website
  • Fargo Village Website

    Mazing Ltd | Logo DesignWebsite DesignWordpress DevelopmentWordpress Plugin Creation
    View Website

Marketing is the message

Digital Design & Dev

I design websites that are clean and easily viewable on all devices. I build the websites using the CMS platform WordPress from the ground up with Thesis and Bootstrap, adding custom functionality through bespoke plugins.

I have a tried and tested method and workflow building WordPress websites, which ensures delivery on time and budget and utilises the latest SEO tricks.

Art Direction & Branding

I love coming up with the idea that will achieve your marketing goals and seeing it through with solid Art Direction.

My logo and branding design has been featured in the publication, Los Logos (the bible of Logo Design around the world) and encompasses all facets of the branding workflow, from company naming, tagline creation, logo mark, roll out to stationery and branding guidelines.

Inbound marketing

Attracting customers instead of interrupting them is key in an age of so many interruptions. How we fish for leads through rich, educational media is vital in telling our story and creating customer loyalty and engagement.

Outbound is dead, long live inbound!

I enjoy working with client of all sizes, adding value to individuals businesses to large global organisations.


Baz Jobson


Art Direction + Branding
Wordpress + Front End Dev
Digital + Inbound

Hit me up