Video embeds

9 September 2014, 15:36

Keywords: video, embed, youtube

The latest Wordpress version makes embedding videos very easy. For example:

Check out this cool video:

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

That was a cool video.

will automatically be turned into a YouTube embed.

Want it in Textpattern? Then replace <txp:body /> in the appropriate article forms by

<txp:etc_query data='<txp:body />' query="*" functions="urlencode">
	{self::*[not(starts-with(., 'https://www.youtube.com/'))]}
	{self::*[starts-with(., 'https://www.youtube.com/')]&=<txp:etc_query url="https://www.youtube.com/oembed?url={urlencode(string(.))}&format=json" markup="json" query="html" />}
</txp:etc_query>

and enjoy the result:

Check out this cool video:

That was a cool video.

File(s)