Discourse + WordPress embed block

The new WordPress editor (Gutenberg; now in core) has a variety of default “block” types, and one of these is an embed block. It works similarly to Onebox — paste in a link and it automatically formats an embed.

Currently, unlike with Onebox, it seems to only work with preset whitelisted sites / link types e.g. YouTube Vimeo, Twitter, Facebook, Instagram, and a couple dozen others.

Rough idea: I’m wondering if it might be possible to add similar functionality for embedded Discourse links in a WP site.

Not sure it’d be possible to extend the core recognized embed types (defined here) to support Discourse, as it looks like these are based on regex domain match and there’s no way to know just from a URL if a site is Discourse.

But maybe this could be incorporated in WP Discourse — extending the Gutenberg embed functionality to automatically recognize and parse for embed any link from the connected Discourse site.

Basically enabling a sort of “reverse oneboxing” so that any Discourse forum topic pasted in a WP blog post / page would automatically display as a nicely formatted embed.

1 Like

This feels like a fairly incomplete solution. It assumes that you’re only ever going to embed from your own Discourse instance. It would need some form of federation between instances to be in place beforehand to be effective.

I think the idea here is that blocks can be used to replace what could only be done with shortcodes in the past. For example the wp-discourse-shortcodes discourse_topics shortcode could be replaced with a block. A similar approach could be used for embedding a post. I don’t think this should be done by embedding an iframe - the topics or posts should be pulled from Discourse as JSON via the API and then converted to HTML.


Agree; now that I think about it, long term a really cool solution would be for WordPress to adopt more robust embedding support (a la Onebox) natively for any external site with the requisite opengraph data. But I know that’s a whole separate discussion on the WP side :slight_smile:

I do think a more limited solution with WP Discourse, enabling topic blocks to embed a post, could still be pretty useful for site with tightly coupled WorPress + Discourse sites that reference each other often. For the use case I imagine it’d almost always be me wanting to embed a discussion from my own Discourse instance on a WP page.

Block-type replacement for the kinds of shortcodes you mentioned sounds cool @simon, will keep an eye for something like that! (Or depending if you’ve already started looking into this, maybe I’ll try hacking on this at some point as an excuse to check out the new WP editor + learn JS in more detail)

1 Like

Agree. We’d probably use it fairly often.

1 Like