Video Thumbnails plugin mod to store youtube ids
-
I’ve added a few lines of code after line 165 as shown below to allow me to store the youtube video id to a custom field so i can recall it later in my theme as a thumbnail linking to the youtube video url. Then i use colorbox to open the youtube embeds in a lightbox modal.
//this is my mod to the plugin
// If we've found a YouTube video ID, create the thumbnail URL if ( isset( $matches[1] ) ) { add_post_meta( $post_id, '_video_id', $matches[1], true ); add_post_meta( $post_id, '_video_service', 'youtube', true );
//and this is the part of my theme
$video_thumbnail = get_the_post_thumbnail( $post->ID, "_video_thumbnail"); if($video_thumbnail){ $video_id = get_post_meta( $post->ID, '_video_id',true); echo "<div class='vid_thumb'>{$video_thumbnail}<a href='https://youtube.com/embed/{$video_id}?autoplay=1&rel=0'>Play Video</a></div>"; <style> .vid_thumb { width: 120px; height:90px; overflow: hidden; float: right; position: relative; margin: 0 0 2px 1em; } .vid_thumb a { position: absolute; display: block; background: url(/img/play_button.png) no-repeat center center; width: 100%; height: 100%; overflow: hidden; text-indent: 100%; overflow: hidden; white-space: nowrap; z-index: 9999; top:0; left:0;} .vid_thumb img { width: 100%; height: 100%; overflow: hidden; } </style>
I hope this helps somebody who is trying to achieve a similar goal. Feel free to incorporate or modify this code however you like, without warranty.
- The topic ‘Video Thumbnails plugin mod to store youtube ids’ is closed to new replies.