Creating oEmbed-Based shortcodes

Adding this snippet to the functions.php of your wordpress theme will create a youtube shortcode. This is a simple sample of an oEmbed-Based shortcode.

 

 

add_shortcode( 'youtube', 'my_youtube_shortcode' );
function my_youtube_shortcode( $atts ) {
global $wp_embed;
if ( empty($atts['id']) )
return '';
// Construct the YouTube URL
$url = 'http://www.youtube.com/watch?v=' . $atts['id'];
return $wp_embed->shortcode( $atts, $url );
}

[youtube id="000000"]

Be Sociable, Share!

Leave a comment