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

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *