I’m making a theme where some posts have an associated video, from either Vimeo or YouTube. At the moment, users can add this to a post by adding a video ID into one of two custom fields, called (surprisingly enough), 'YouTube' and 'Vimeo'. My theme then takes this info and adds it to the standard embed code for these sites, and outputs it on the post page.
However, I’d like to make things easier for the users of the site, if possible. I’d like to replace these two fields with a single custom field, and also allow them to enter the full URL of the video on Vimeo or YouTube (instead of the ID).
I presume that this would require two things: firstly, that the URL is recognised as coming from either Vimeo or YouTube, and secondly, that the rest of the URL is stripped, so that I can use the ID to output the embedded video nice and clean on post pages.
I know that there are plenty of plugins that do this kind of thing (and other similar things) automatically, but I’d prefer to have this built-in, if at all possible.
I’m not a PHP wizard so I haven’t ventured into doing anything about it yet, but I’m hoping that this could be made to happen via some functions.php magic.
Anyone have any ideas about the best way to proceed?
Thanks.