Tip
The Twitter timeline may fail to display in certain scenarios, however, this error comes not from Twitter and not from Hugo or this shortcode. A common cause of error is if Twitter fails to retrieve sufficient login credentials in the browser client when serving requests on a webpage. As of 25th December 2023, this has not been fixed on Twitter's end.
A simple Hugo shortcode for embedding a Twitter timeline, based on the Twitter widgets code, which can be accessed via https://publish.twitter.com/ and https://platform.twitter.com/widgets.js
The supported parameters are
username
: The username of the Twitter account to embed the timeline for (required)language
: The ISO 639-1 language code for the language in which to render the timeline (see Supported languages and browsers – Twitter for Developers for more information), set automatically by Twitter if not specifiedwidth
: The width of the timeline in pixelsheight
: The height of the timeline in pixelsdonottrack
: Whether to enable the Do Not Track feature, eithertrue
orfalse
– defaults totrue
to preserve your privacytheme
: The theme to use for the timeline, eitherlight
ordark
– defaults tolight
To use the shortcode, simply add the following to your Hugo content file(s) and/or customise as needed:
{{< twitter-timeline username=twitter language=en width=500 height=800 donnottrack=true theme=dark >}}
assuming that the shortcode is saved as twitter-timeline.html
in your Hugo theme's layouts/shortcodes
directory.
This project is licensed under the MIT License.
Please feel free to use it across your projects and star this repository. If you have any questions or suggestions, please feel free to open an issue or a pull request.