Skip to content

Instantly share code, notes, and snippets.

@retlehs
Created May 25, 2012 02:17

Revisions

  1. retlehs created this gist May 25, 2012.
    21 changes: 21 additions & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?php
    /**
    * Display a thumbnail from YouTube based off the embed code saved in the
    * video post format metabox used by the CF Post Formats plugin
    *
    * @link https://github.com/crowdfavorite/wp-post-formats
    * @link http://stackoverflow.com/a/6382259
    */

    global $post;

    $video_details = get_post_meta($post->ID, '_format_video_embed', true);

    if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_details, $match)) {
    $video_id = $match[1];
    }

    if (isset($video_id)) { ?>
    <a href="<?php the_permalink(); ?>"><img src="http://img.youtube.com/vi/<?php echo $video_id; ?>/0.jpg"></a>
    <?php }
    ?>