Embed YouTube video from custom field value

I’m collecting Youtube video links in custom fields, but when I echo out the value it just prints the URL. How do I get WordPress to convert it to be embedded?

Example:

Read More
<?php global $post;
$video = get_post_meta( $post->ID, '_my_video_link', true );
echo ( $video ); ?>

Just outputs http://www.youtube.com/watch?v=tkEvSjdDfiA

But I want it to display the actual video…

Thanks for any advice

Related posts

1 comment

  1. Aha! WordPress has a built in function for it 😀

    <?php echo $embed_code = wp_oembed_get( $video ); ?>
    

    Simples.

Comments are closed.