Uncategorized

Embed youtube videos, the easy way!

I just found a neat piece of code I want to share.

If you want to let your client embed youtube videos and don’t want to make it to complicated for them make them a Backend textfield where they past the Video URL.

With this call $video = json_decode(file_get_contents(sprintf(‘http://www.youtube.com/oembed?url=%s&format=json’, urlencode($url)))), you get an object congaing most info you will need about the Video.

$video->html gives you the embed code, $video->title, you guessed it,  the title.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s