PunBB forums: How to embed single tweets


Pretty basic - I would like my forum users to be able to embed single tweets. Grabbing a fresh sports tweet and adding it to their message would definitely enhance conversation.

Everything that is added to posts in punbb is through bbcode tags.

I have previously tried to achieve this without utilizing any bbcode and was unsuccessful. Any help would be greatly appreciated.


Many content systems supporting freeform entry of HTML strip out <script> elements. Tweet embeds rely on Twitter’s widgets JavaScript to render the full Tweet.

I am not familiar with BBCode macros but have written similar shortcode handlers for WordPress.

You may have special markup such as [tweet id="792752854192775168"]. Your macro processing code would extract the Tweet ID from the id attribute, provide some basic validation, and request markup from Twitter’s oEmbed-compatible API. You might choose to omit the returned <script> component and instead register Twitter’s widgets JavaScript with PunBB’s preferred resource loader.

Once you have the fallback markup you’ll ideally cache it so you’re not making a server-to-server request to Twitter’s oEmbed API with every page load.

If you’d like to get advanced you would recognize the possible <blockquote class="twitter-tweet"> markup that could be posted into an editing area, extract the Tweet ID within, and store as a BBCode macro. Liberal in what you accept, conservative in what you store, etc.

The embedded Tweet CMS best practices guide on our developer site has some more information.


The blockquotes and html markup will not work within a single post.

After looking at both of those links you have provided, the information does not seem to work in the direction I am trying to go.

I need a functionality that makes it so that my users can use the tweet’s url in a simple fashion to make the tweet appear within a post. Ideally, it would either be with the usage of bbcode tags, or better yet, by simply placing the url in the post and having javascript identify and mark up the url.

If that is the information that you are trying to provide I apologize but the way it is described in those links and the manner in which it is presented makes it extremely difficult to decipher.

And for the record, thank you for taking the time to help me with this.


WordPress runs a filter on the post body before output, looking for a URL on its own line or content surrounded in square brackets to be processed as a shortcode. It’s possible PunBB has something similar.

A URL on its own line can be processed by a generic oEmbed handler or your own code.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.