Skip to content

Instantly share code, notes, and snippets.

@eto4detak
Created September 8, 2018 11:35
Show Gist options
  • Save eto4detak/333471214c6734f974f32557ab269d95 to your computer and use it in GitHub Desktop.
Save eto4detak/333471214c6734f974f32557ab269d95 to your computer and use it in GitHub Desktop.
youtybe php
<?php
// $YoutubeCode = get_the_content();
$YoutubeCode = 'https://youtu.be/COwlqqErDbY';
$YoutubeCode = 'https://youtu.be/COwlqqErDbY';
preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $YoutubeCode, $matches);
if (isset($matches[2]) && $matches[2] != '') {
$YoutubeCode = $matches[2];
}
echo '<img src="http://img.youtube.com/vi/' . $YoutubeCode . '/0.jpg" />';
echo '<iframe src="https://www.youtube.com/embed/'.$YoutubeCode.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment