Knowledge Base: Embedding Media in Posts and Comments

Thanks to a technology called oEmbed, it is possible to embed videos, documents, tweets from Twitter, images from image hosting sites, polls, and other media in your posts on the main site and in groups, and in comments on those posts.

It couldn’t be easier.  For example, suppose you’re viewing an interesting video in YouTube which you’d like to share.  As long as the person who posted the video hasn’t marked it as ineligible for embedding, you simply copy the URL from the address bar of your Web browser, something that looks like “https://www.youtube.com/watch?v=CJ6nn8fZOmc” into your post on a line by itself, without any formatting (such as bold or italic type), and the link address will be automatically transformed into embedded media when you publish the post or comment.

In order for a link to be embedded,

  1. The site linked to must support the oEmbed protocol and,
  2. The site must be on a “white list” of acceptable sites.

The white list for ratburger.org is presently the standard list supplied with a stock installation of WordPress, but sites may be added or removed in the future based upon user requests and experience.  Here is the complete list of sites from which you may currently embed content.  In addition, you can embed links to posts or comments on ratburger.org.

This about 95% of what you need to know.  What follows are more technical details which many users can safely ignore.  But this is the knowledge base, so here’s the knowledge.

Some sites, for example YouTube and Twitter, will give you “embed code” which often starts with something like “<iframe”.  This is not what you should paste into your post or comment.  That is intended for sites which do not support oEmbed but rather require you to paste the raw HTML (the markup language for Web documents).  Ratburger, like most modern WordPress-based sites, fully supports oEmbed and does not permit raw HTML in posts.  Simply post the URL from your browser’s address bar on a line by itself, and the site will take care of all of the details of embedding.

But how does it work, you ask.  The oEmbed protocol is clever.  Upon encountering what looks like a URL in text, and determining that it references a site our white list allows embedding, a special request is sent to that site for the embed code for that URL.  If the site recognises the URL and permits embedding it, it supplies the HTML code to be inserted to embed the media in the page.  This step should make it abundantly clear why a white list is necessary: without massively complex parsing and analysis of this HTML, there’s the possibility it might contain malicious code which could damage the user’s computer or compromise privacy.  Consequently, embedding is restricted to sites with deep pockets where the damages from such misbehaviour deter them from engaging in it.  (In other words, “Don’t be evil, or we’ll sue you into the stone age”.)

Finally, what if you want to cite a URL, but not have it embedded?  This happens frequently when writing about resources on the Web or documenting work which cites them.  It’s beyond irritating to try to provide the user a URL and have it expanded into a box which disrupts the flow of the text.  When I first encountered this, I slew more thesauruses than the Chicxulub impactor trying to express my distaste for this: my favourite was “the mephitic URL expander”.  The secret lies in recalling the phrase “on a line by itself, without any formatting”.  To cite a URL without invoking oExpand, simply break one of these rules.  The easiest way is to work it into your text, quoted, for example, as I did in the second paragraph of this post.  You can also simply precede the URL with a period, which few people will notice, but which breaks embedding of the URL.

.https://www.youtube.com/watch?v=CJ6nn8fZOmc

5+

Users who have liked this post:

  • avatar
  • avatar

Author: John Walker

Founder of Ratburger.org, Autodesk, Inc., and Marinchip Systems. Author of The Hacker's Diet. Creator of www.fourmilab.ch.

One thought on “Knowledge Base: Embedding Media in Posts and Comments”

Leave a Reply