-
-
Save Firestorm-Graphics/2959626 to your computer and use it in GitHub Desktop.
Display YouTube thumbnail from embed URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 } | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment