Get Embed from Youtube or Vimeo URL

Here’s a function I’ve used on quite a few times. If you have the URL of a Youtube video, from a Custom Meta Field, or a field in a Custom Settings Page or custom meta box, you can run that user-supplied URL through this function and get the source code for an embedded video:field

I’ve also done this for Vimeo videos, below is from a project I worked on using Vimeo’s API, untested but it should work:

If your user supplied URL could be either of the two, strpos() or another find function could detect which and use either of the above.


Leave a Reply

%d bloggers like this: