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.
 
So when we post an internal link it automatically uses the embed feature instead of the unfurl, correct? Or is that a setting in acp? Or do we have to instruct users on using embed? (Sorry if I missed the answer.)
 
So when we post an internal link it automatically uses the embed feature instead of the unfurl, correct?
Yes, that seems correct based on Chris D's post below (specifically the part I have made bold):
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:



How customizable will embeds be design wise?
Taking a cue from URL unfurling to include an icon-sized logo and domain name (or at a minimum just an icon) would be ideal in my opinion for external embeds. E.g.:
xenforo-url-unfurl-favicon-and-domain-name.gif

Without something like this I think it would be difficult to determine the origin of an embedded post (or other content type) ... particularly if an external website embeds content from multiple XenForo-powered communities.
 
I am anxious to extend the embed and use it with my moderator panel add-on.

Is there going to be a permission check. For example, if an user gets a hold of the share link I wouldn't want them to able to view if they shouldn't be able to.
 
Nice. I disabled URL unfurling on my forum because I don't want it to be automatic (and I don't think there was any info telling you that it only does it when a link is on its own line). Even though this embed option isn't exactly the same, it seems like it should be the "manual URL unfurling" I've been wanting.

If I understand correctly, the limitation/difference is that the embed option only works for content on your forum, and looks a bit different?
 
I would like to be able to turn the feature on or off. I would set mine to off, as my members DO NOT want their mental health content easily shareable across the internet. Easy to share on the site, yes. Off the site, no.
 
This feature doesn't fundamentally change how sharing content to external sites works.

Unfurling has always been possible, but it has been for the first post on the page.

If you don't want content shared outside the site, remove the view permission for guests.

Even then, anyone can simply copy and paste content to anywhere on the internet ...
 
This feature doesn't fundamentally change how sharing content to external sites works.

Unfurling has always been possible, but it has been for the first post on the page.

If you don't want content shared outside the site, remove the view permission for guests.

Even then, anyone can simple copy and paste content to anywhere on the internet ...
Unless they have one of those annoying anti-right click dialogues from the early 00s.. (Which is primitive protection, really)

"dOnT STeAL mY sTufF!"
 
Unless they have one of those annoying anti-right click dialogues from the early 00s.. (Which is primitive protection, really)

"dOnT STeAL mY sTufF!"
My writing sites use it for the stories. Not sure how much good it does but they added a bunch of lockdown features when they switched software in 2021 because the NSFW site (i.e. for erotic stories) was having issues with stories getting scraped. Bit of a nuisance because it means if I want to copy part of one of my old stories for something, I have to go into the editor to do it.
 
How about "copy to clipboard" button for quick copy of post?
I usually have a copy option in my native share app settings on android. If I press share I usually get a "copy link" option.

Not saying your idea doesn't have merit but it's mostly already doable using native browser functions.
 
This is probably a dumb question and may have already been answered but the old bbcodes will still work right?
 
Top Bottom