Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save webgurus/4e550a050f9697f8215ecb62b25e0768 to your computer and use it in GitHub Desktop.
Save webgurus/4e550a050f9697f8215ecb62b25e0768 to your computer and use it in GitHub Desktop.
function custom_youtube_oembed_lite($html, $url, $args) {
// Check if the URL is a YouTube link
if (strpos($url, 'youtube.com') !== false || strpos($url, 'youtu.be') !== false) {
// Extract the YouTube ID from the URL
preg_match('/(youtube\.com\/watch\?v=|youtu\.be\/)([^\&\?\/]+)/', $url, $idMatch);
$youtubeId = $idMatch[2];
// Return the Lite YouTube Embed HTML
return '<lite-youtube videoid="' . esc_attr($youtubeId) . '"></lite-youtube>';
}
// Return the default embed HTML for non-YouTube URLs
return $html;
}
add_filter('embed_oembed_html', 'custom_youtube_oembed_lite', 99, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment