Hugo Custom Shortcodes

Before going to custom shortcodes, you need to unnderstand what is a shortcode in Hugo.


Shortcodes are a way to insert templates into your content files, as explained on Hugo website. They allow you to add features that are not supported by Markdown, such as YouTube videos, images, info cards, and more. Instead of using raw HTML, which breaks the simplicity of Markdown syntax, you can use shortcodes to achieve the same results. Shortcodes are also easy to update and modify, as Hugo will apply the changes when building your site.

In addition to cleaner Markdown, we can update the shortcode anytime with new changes and Hugo will reflect the same in the time of building.

Custom Shortcodes

There are few shortcodes is readily available in the Hugo like figure, gist, tweet, vimeo, etc for various purposes. Hugo’s built-in shortcodes cover many common, but not all use cases. Luckily, Hugo provides the ability to easily create custom shortcodes to meet your website’s needs.

To create a custom shortcode, place an HTML template in the layouts/shortcodes directory of your source organization.

Below are some of the custom shortcodes I created for my website. Please feel free to check the below and use the same if you like it.

Card shortcode

Shortcode for displaying card with text and links.

Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow and Discourse.

Shawn Wang

Writer, Speaker, Developer Advocate. He help developers to Learn in Public!

Maggie Appleton

Maggie makes visual essays about programming, design, and anthropology.

Read this for more details and code.

Image shortcode

Image short code which will replace existing figure shortcode and render the image with caption and link.

Tree of Life Photo by Bino
Tree of Life / Bahrain

Image shortcode

Read this for more details and code.

Info card shortcode

Card for displaying information in the blog post.

What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Read this for more details and code.

I hope I will create and share more custom shortcodes as the new requirements is coming.

Read More