Pack of Shortcodes for Hugo

GeekThis remains completely ad-free with zero trackers for your convenience and privacy. If you would like to support the site, please consider giving a small contribution at Buy Me a Coffee.

Today I’m releasing a pack of custom shortcodes for Hugo. A shortcode is a special tag added to a post that will embedded content or add HTML to a post instead of having to manually add the HTML. A few examples of shortcodes include YouTube, Vimeo, and GitHub Gists. The pack I created adds the ability to embed Google Maps, Box Document Preview, Pastebin, Twitch videos, Twitch livestreams, and JSFiddle. I’m going to keep adding new shortcodes in the future as I come across new sites that will work well with shortcodes.

Installing Shortcodes

Installing new shortcodes to Hugo is very simple. Depending on where you want the shortcode stored, you will have to adjust the directory you add the shortcodes to. Generally I recommend installing shortcodes into the layouts directory instead of adding them to themes. The downside of adding the shortcode to a theme is that in the future when you change themes, those previously used shortcodes will no longer work unless you copy them to the new theme.

To install shortcodes to the layouts directory, follow the steps below. If you decide that you want to install the shortcodes to a theme instead (for instance if you are releasing a theme to the public) replace the layouts directory with the layouts directory located inside of you theme’s directory.

  1. Download and extract the Hugo Shortcode Pack at the bottom of this page. Depending on your operating system, you can usually right click on the file and click on “Extract.”
  2. Copy the shortcodes from inside of the layouts/shortcodes directory into your Hugo directory that goes by the same name. Create any of the directories don’t exist.
  3. The shortcodes are now installed. You can test them by adding our sample post that is located in the folder content/post to your blog. Once you are done testing the shortcodes, it’s safe to delete this file as it’s not needed.

For additional information about Hugo shortcodes, you can read Hugo’s Shortcode Documentation to learn more about shortcodes and learn how to create you own.

Included Shortcodes

Below is a list of the shortcodes that are included in this pack. In the future I’m going to add even more shortcodes when I come across an interesting site that can be embedded or when I create a shortcode for my other sites that use Hugo.

  • Twitch Embedded Video
    • Embeds a past broadcast from Twitch to your website.
    • Maintains a 16:9 aspect ratio.
  • Twitch Live Stream
    • Embeds a live stream player from Twitch to your website.
    • Maintains a 16:9 aspect ratio.
  • Pastebin
    • Displays a paste that was added to Pastebin directly on your site.
    • Includes an option to set a max-height of the paste.
  • JSFiddle
    • Displays a JSFiddle that was created. Can be customized to show different tabs such as JavaScript, HTML, CSS, and the final result.
    • Customize viewable tabs.
    • Customize appearance to be light or dark mode.
  • Google Maps
    • Displays an embedded Google Map of any location that you can search for. Works for display a city, address, business, or a street.
  • Box Document Preview
    • Displays an embedded document preview of any file shared on Box. Works with PDF, DOC, Spreadsheets and many other formats.

Each shortcode has multiple options that makes them easy to customize. Included in the downloadable archive is a sample post that shows the various options available for each shortcode. For designers and developers out there, each shortcode has a div element as a container with class attribute set to .shortcode along with each shortcode having a unique class name. This should make formatting the position of the shortcodes easier. Each shortcode is also designed to fill the width of the container.

Show Your Support

If you enjoy these shortcodes and are using them on your site, please link back to I would really appreciate being part of your blogroll or being mentioned in a blog post or on social media. Mentioning this site helps out a lot and allows me to keep creating and updating these free resources along with writing blog posts.

Related Posts

Hugo Footnotes and Citations

Add footnotes, citations, and references to your Hugo posts with this simple technique. Give your articles more credibility and improve your posts by making them more informative.

Generating Random Numbers, Strings, and more in Hugo

Create random numbers, random strings, fetch random items in slices, and generate repeatable seeds within the Hugo static site generator.

How to Separately Handle Multiple Website Deployments

Learn how to configure your computer to run multiple website deployments with rsync and multiple Linux accounts.

Build Script for Hugo Websites

A basic bash build script for Hugo websites to compress images, JavaScript files, and CSS before releasing your website to the public. Keeps a copy of uncompressed assets while easily compressing all files before uploading your website.