Select Page
Oembed as Post Meta – WordPress Code

Oembed as Post Meta – WordPress Code

I feel as though recently I’m always blabbing to my peers about Oembed. Seems this is a typical thing for me to blab about the latest code I’m working on :p I don’t think it’s a bad thing, but I’m probably like that old man that just keeps repeating the same thing over and over! I know I will be him!!

Anyway, here is an example plugin that I put together from my core theme that utilized WordPress WP_oEmbed() class. There is a basic metabox class that houses a field for the video url. On “save_post” it will take the url and run it through WP_oEmbed() and return the data. It will save the url and the video thumbnail as custom fields as well as the full data array returned. (Currently only vimeo and youtube are guaranteed to pull thumbnails, it really depends on the service, but the full data array is stored so you know it exists.)

The reason I built this was so that the users could have a pseudo featured video, plus it provided it’s own image. This version is a demo plugin since I’ll be the alternate speaker at WordCamp Nashville 2012.

Here is the code, have fun and let me know if you see any errors. ps github always messes with tabs so sorry if it’s all out of whack