Embedding tweets

I was wondering if there was a way to “embed a tweet” into a post.

I know that embedding in general is possible, via Hugo shortcodes: using {{< youtube ... >}} works.

However, using the {{<tweet user="..." id="..." >}} shortcode doesn’t; the failure is having something like HAHAHUGOSHORTCODE-0xc000e7f900-1-HBHB show up in the rendered output.

So, Is this something that’s supposed to work?

(Has anyone ever embedded a tweet? Is there a reason why shortcodes are treated differently?)

Thanks,
Agam

I embedded a tweet successfully just now. So it’s supposed to work.

However, how you use the shortcode differs depending on the Hugo version. You can see your blog’s version by navigating to Design and looking for the label Hugo version.

Embed a tweet using Hugo 0.54:

{{< tweet 20 >}}

Embed a tweet using Hugo 0.91:

{{< tweet user="Jack" id="20" >}}

Doing the above ended up looking like this on my test blog:

3 Likes

Hi! This is an only somewhat related follow up question. If I need to start a new thread, please let me know.

I’m trying to embed something from Apple Music. I’ve found blog posts, etc. related to creating a custom shortcode. Would I need to do that in order to embed Apple Music stuff? Is that even possible to do with micro.blog?

<iframe allow="autoplay *; encrypted-media *;" frameborder="0" height="450" style="width:100%;max-width:660px;overflow:hidden;background:transparent;" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation" src="https://embed.music.apple.com/us/album/smile/24245496"></iframe>

Yes, pasting in the Apple Music embed code should work fine in a Micro.blog blog post. Note that the full iframe tag is not supported in the Micro.blog timeline, so instead Micro.blog will try to make it a link to Apple Music. But on your actual microblog on the web it will look correct.

Did this stop working just recently?

The form of

{{< tweet user=“Jack” id=“20” >}}

was working fine for a while with Hugo 0.91 default theme. Now it’s failing with errors.

Theme error: Error building site: “/rym_1e3793/content/2022/12/16/usertorriangray-id-this.md:9:1”: failed to extract shortcode: template for shortcode “user” not found

It’s hard to help you without seeing the actual content of your post. But the error message you share indicates your source looks like this (without tweet):

{{< user="Jack" id="20" >}}

@sod is almost definitely correct, but I also want to warn about using the Twitter shortcode (which I like and have used as well!): if the user deletes their account or the tweet is deleted, it will cause a build error. With more people fleeing twitter, this has become more common and is something to consider.

1 Like

I’m with you on this one: a regular quote is better for posterity. Quotebacks is nice!

Agree with Sven and Jason. I started using Quotebacks for tweets, because I ran into Hugo build errors and had to go through hundreds of posts to find the ones with embedded tweets and take them out.

I’ve never had an issue with using shortcodes for embedded YouTube videos, though, which is good because their iframe embeds are not responsive.