4

Is there any easy way to detect if an oEmbed URL is still returning any content? And, if so, is there a way to replace the missing oEmbed content with some kind of fallback content?

For instance, if I paste an instagram.com URL in my post, WordPress will recognize it and use oEmbed to inject Instagram's embed widget into the blog post. This provides a nice rich experience for visitors with a description, tags, a link to the person that posted the image on Instagram, etc.

However, as time goes by, there is an increasing chance that some users will remove their old images from Instagram. Once that happens, there won't be anything to embed and the blog post will no longer have an image at all. In such cases, I would like to be able to detect the (un)availability of oEmbed content and provide a graceful fallback, such as a locally stored image.

If anyone knows how to achieve this, some help would be highly appreciated.

1 Answer 1

1

Probably impractical. When you do not control the content you can not know if it will be embedable at the time of viewing. Easiest example of why it might be hard in the context of youtube/vimeo is videos that can become restricted, either private or geo restricted. In that case the content is still embedable but the user sees some kind of "this content is restricted" message. At this case you might want to show you alternative content, but it is impossible to detect such an event on wordpress side. Youtube has JS API which might give you relevant indications, but not all service providers has such an API (wordpress oembed server part of the code do not have such a thing AFAIK)

You can detect content removal by trying to execute the oembed protocol once every several days for all posts, but assuming that there is no scaling problem to do that, what will you exactly do when an oembed fails? you can not replace a video or a song with alternative content, and using an instagram image from your server is a copyright violation.

If you are worried about such a thing, do what CNN does when they embed tweets where they copy the text of the tweet as part of their content, in other words - if you have an alternative content, just use it on the side of the embedded one.

3
  • At first I was mainly thinking of where to even start hooking into Wordpress' oEmbed features. But I soon realized things get real complicated real fast. Commented Sep 12, 2016 at 17:17
  • @RubenRayVreeken, wordpress caches the result of the oEmbed every time the post is changed. Doing anything like that every time the page is viewed might overload the server. Probably the best general approach is to test for broken oEmbed like you test for broken links, but the question of what replace it with is the really hard one to figure out. Commented Sep 12, 2016 at 17:41
  • Yeah I think this is just one of those things that are way too complex to spend the time to build a great solution, considering the fact that embeds don't usually go online often enough to be a big problem and there is no clear idea of what the alternative content should be. Commented Sep 13, 2016 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.