XF 2.3 Embed your content anywhere

This week, we're delighted to introduce a new feature in XenForo 2.3 that enhances the way you can share content on your forum. Plus, we'll show you how easy it is to share any content from your forum to other platforms using our new content embedding feature.

Rich previews for content​

If you're already familiar with URL unfurling, content embedding works similarly. In XenForo 2.2, when you post a link to content on your forum, we perform an HTTP request, download a portion of the content, and extract metadata such as the page title, description, and a logo. If you need a refresher on URL unfurling, you can find our original announcement from XenForo 2.1 here:


While URL unfurling works well for content from other sources, for content already on your forum, we're introducing a new [EMBED] BB code. This fetches a rich preview directly, and is added to your content automatically on save if you paste a link (on its own line). This is what it looks like:

hys_7_content_embed_1.png


A minor inconvenience with the unfurl system when sharing content on your forum is that it sometimes misses the context. For example, if you link to a specific forum post, the unfurl system retrieves metadata from the thread instead of the post itself. With our new content embedding system, this issue is resolved. Now, when you want to feature a specific post, the system generates a rich preview of that post, preserving the context and enhancing the viewer's experience:

hys_7_content_embed_2.png


Of course threads and posts are not the only content supported. You can also embed profile posts:

hys_7_content_embed_3.png


Resources and resource updates:

hys_7_content_embed_4.png


hys_7_content_embed_5.png


And, of course, media items and albums which are mostly the same as they were previously with the existing [GALLERY] tag:

hys_7_content_embed_6.png

hys_7_content_embed_7.png


You might already be thinking about the possibilities this opens up for developers. As always, developers are welcome to add support for their own content types in the usual way.

We're eager to hear what you think about these updates. But don't go just yet; we've got more to share.

Embedding content anywhere​

In addition to improving how you highlight content on your forum, you can now also embed your content on other forums or even non-XF content management systems.

Included in XenForo is a new script named embed.php. This script allows your content to be rendered anywhere, as long as it's visible to guests. All you need is the content type and ID and an iframe:

HTML:
<iframe src="https://xenforo.com/community/embed.php?content=thread-216767" frameborder="0" width="560"></iframe>

hys_7_content_embed_8.png


For a more accessible approach, you can find the embed code for a specific item under the share tooltip (where available):

hys_7_content_embed_9.png


This version of the embed code looks like this:

HTML:
<div class="js-xf-embed" data-url="https://xenforo.com/community" data-content="thread-216767"></div>
<script defer src="https://xenforo.com/community/js/xf/external_embed.js?_v=ab87d886"></script>
This embed code does the same job as the iframe, but with a little extra magic to make sure the iframe sizes itself perfectly to fit the content.

This new ability to externally embed content means you can now implement a BB code media site in your XenForo forum to automatically embed content from other XenForo forums!

Furthermore, starting with XenForo 2.3, we're introducing a new oEmbed endpoint to our REST API. This endpoint doesn't require authentication and is always available. For example, a request to https://xenforo.com/community/api/oembed/?url=https%3A%2F%2Fxenforo.com%2Fcommunity%2Fthreads%2Fboosting-performance-in-xenforo-2-3.216767%2F will produce the output:

JSON:
{
    "version": "1.0",
    "type": "rich",
    "provider_name": "XenForo community",
    "provider_url": "https://xf.deemit.site/community",
    "author_name": "Chris D",
    "author_url": "/community/members/chris-d.11388/",
    "html": "<div class=\"js-xf-embed\" data-url=\"https://xenforo.com/community\" data-content=\"thread-216767\"></div><script defer src=\"https://xenforo.com/community/js/xf/external_embed.js?_v=ab87d886\"></script>",
    "referrer": "",
    "cache_age": 3600
}

In addition to oEmbed making it easier to embed your content on other XenForo forums, it will also make it easier to post your content almost anywhere. For example, if you were to get your forum approved by Embed.ly, your content could end up being shared with rich previews on platforms such as Reddit, and many more!

That wraps up this week's HYS! We look forward to hearing your feedback and will be back with more next week.
 
We use the web share API where supported, and what appears there is entirely up to your OS.

The fallback share menu, which appears on most desktops, has the embed HTML. I imagine it’s far less applicable for typical mobile use anyway.
 
Oh, then can you provide further details? What exactly you tried, what was the expected behavior, what was the actual result, etc.

The embed HTML appears in the share tooltip (on desktop) and seems to copy to the clipboard correctly. I haven’t tested it on an external site yet though.
 
To get embed code on mobile browser, you would need to turn on desktop browsing mode. Xenforo ignores web share api and opens the pop-up that lets you copy post link or embed code as designed. In mobile browsing mode it uses web share api and opens the native share popup. Android one has option to copy link. iOS should have it as well. But you don't get the html code to embed content in external sites.
 
Oh, then can you provide further details? What exactly you tried, what was the expected behavior, what was the actual result, etc.

The embed HTML appears in the share tooltip (on desktop) and seems to copy to the clipboard correctly. I haven’t tested it on an external site yet though.
Not really interested in going into detail as I'm not a ALPHA/BETA tester for XenForo, simply a licensed user.
Tried to post a link in a conversation to a "forum specific" post that originated on the site here... and it resulted in a crap response that had a lot of excess BBcode in it using the Copy embed code HTML link provided via the editor. Using the Copy Link share code from the site EVENTUALLY provided a FURL (originally in the conversation it was a URL).
 
Embed code provided by xenforo share pop-up is html so it is not for use in forums which use bbcode instead.
And one would think that XF would be smart enough to detect the difference, especially if it is originating locally and they are offering it as a "choice" in the "sharing" offering that is available to every SD that uses that function.
You (by your post) put a LOT of expectation of knowledge upon the end users. Why should they have to "figure" out if they need to use BBCode or HTML to post to another XF (or any other) site? Should not the script be smart enough to figure that out, especially if coming from one XF site to another (never mind if it's the very same site itself)?
 
Last edited:
Well. While I understand your point… Forum applications like XenForo have never accepted HTML code in their post editors. Users are always expected to paste links and embeds are handled by the forum software itself. Twitter or YouTube embed codes won’t work if you paste it here. It has always been like this. And anyone who has used forums for a few years are expected to understand it. If not, they would end up with gibberish content and they would be notified by mods to just put link of external sites instead of posting embed codes. I still get some users who would post embed codes and I have to fix it and send them a message about this.

In the end, forums are not really mainstream so yes, regular folks are not expected to understand the difference between BBCode and HTML Code and what is applicable where. But there is no easy way to fix this. I mean embed codes would not work on mainstream social platforms like Twitter or Facebook so generally speaking, most folks are expected to just post a regular link.

The problem you highlight is also not easy to resolve. XenForo embed codes are not going to work on third-party XenForo installs. It would also not work on other forum software. Pasting a link of a post from one XenForo forum on another would also not work. Embed of local content is automated if enabled by the admins on 2.3 installs. External content even if from another XenForo 2.3 install would be treated like any other link and would get a regular unfurl.

In the end, embed codes are basically for advance users who might want to embed a post on their websites where they have the ability to put HTML code including JavaScript which is essentially never allowed for user generated content like in blog comments or forum posts. It is just a feature that exists and can be used.
 
we're introducing a new [EMBED] BB code. This fetches a rich preview directly, and is added to your content automatically on save if you paste a link (on its own line)

Is there an option in the Admin control panel to disable the EMBED bbcode?
 
It can’t be disabled itself but you can disable the automatic embedding.

On my forum I don't have enabled:

Unfurl URL to a rich preview automatically

or

Convert URLs to page titles

Is there a similar option for EMBED which we can unchecked?

Also what do you mean by "It can’t be disabled itself" as that is unclear. Do you mean there's a table which gets updated even if the embedding is disabled?
 
The BB code can’t be disabled but the automatic embedding can be. Theoretically someone could manually type the BB code to embed content.

But yes there is a similar option in the same place to disable automatic embedding.
 
does it get a button that can be added to the toolbar in post editor? there isn't one right now here so can't confirm myself. thanks!
 
right. the post share popup also does not include the bbcode version for embedding so if automatic embed is disabled, it is unlikely anyone would be embedding posts manually unless they really want to! good enough i suppose. :)
 
Back
Top Bottom