Created
July 15, 2024 14:00
-
-
Save webgurus/4e550a050f9697f8215ecb62b25e0768 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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