Last active
January 16, 2023 01:30
-
-
Save jruck/4270084 to your computer and use it in GitHub Desktop.
WP: Minimal wp_oembed_get
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
// Minimal YouTube & Vimeo embeds | |
function wp_oembed_get( $url, $args = '' ) { | |
if(preg_match("/youtube.com\/watch\?v=([^&]+)/i", $url, $aMatch)){ | |
return '<iframe width="640" height="360" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>'; | |
} | |
if(preg_match("/youtube.com\/watch\?feature=player_embedded&v=([^&]+)/i", $url, $aMatch)){ | |
return '<iframe width="640" height="360" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>'; | |
} | |
if(preg_match("/youtube.com\/watch\?feature=player_detailpage&v=([^&]+)/i", $url, $aMatch)){ | |
return '<iframe width="640" height="360" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>'; | |
} | |
if(preg_match("/vimeo.com\/([^&]+)/i", $url, $aMatch)){ | |
return '<iframe width="640" height="360" src="http://player.vimeo.com/video/' . $aMatch[1] . '?title=0&byline=0&portrait=0" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; | |
} | |
require_once( ABSPATH . WPINC . '/class-oembed.php' ); | |
$oembed = _wp_oembed_get_object(); | |
return $oembed->get_html( $url, $args ); | |
} |
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
DELETE FROM wp_postmeta WHERE meta_key LIKE '_oembed_%' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. That was very useful.