Built-in Shortcodes

Shortcodes are simple snippets inside your content files calling built-in or custom templates.

What a Shortcode Is

Hugo loves Markdown because of its simple content format, but there are times when Markdown falls short. Often, content authors are forced to add raw HTML (e.g., video <iframe>’s) to Markdown content. We think this contradicts the beautiful simplicity of Markdown’s syntax.

Hugo created shortcodes to circumvent these limitations.

A shortcode is a simple snippet inside a content file that Hugo will render using a predefined template. Note that shortcodes will not work in template files. If you need the type of drop-in functionality that shortcodes provide but in a template, you most likely want a partial template instead.

In addition to cleaner Markdown, shortcodes can be updated any time to reflect new classes, techniques, or standards. At the point of site generation, Hugo shortcodes will easily merge in your changes. You avoid a possibly complicated search and replace operation.

Use Shortcodes

  1. Shortcodes with raw string parameters ` `
  2. Shortcodes with Markdown % %
  3. Shortcodes without Markdown < >

See more details in the Use Shortcodes section.

Embedded Shortcodes

Use these Hugo’s embedded shortcodes as needed.

Tip
To override Hugo’s embedded shortcode, copy the source code to a file with the same name in the layouts/shortcodes directory.

Figure

Documentation of figure shortcode.

Example figure input:

1
{{< figure src="/images/lighthouse.jpg" title="Lighthouse (figure)" >}}

The rendered output looks like this:

Lighthouse (figure)

The HTML looks like this:

1
2
3
4
5
6
<figure>
  <img src="/images/lighthouse.jpg" />
  <figcaption>
    <h4>Lighthouse (figure)</h4>
  </figcaption>
</figure>

Gist

Documentation of gist shortcode.

Example gist input:

1
{{< gist spf13 7896402 >}}

The rendered output looks like this:

The HTML looks like this:

1
<script type="application/javascript" src="https://gist.github.com/spf13/7896402.js"></script>

Highlight

Documentation of highlight shortcode.

Example highlight input:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{{< highlight html >}}
<section id="main">
    <div>
        <h1 id="title">{{ .Title }}</h1>
        {{ range .Pages }}
            {{ .Render "summary"}}
        {{ end }}
    </div>
</section>
{{< /highlight >}}

The rendered output looks like this:

1
2
3
4
5
6
7
8
<section id="main">
    <div>
        <h1 id="title">{{ .Title }}</h1>
        {{ range .Pages }}
            {{ .Render "summary"}}
        {{ end }}
    </div>
</section>

Instagram

Documentation of instagram shortcode.

Example instagram input:

1
{{< instagram CxOWiQNP2MO >}}

The rendered output looks like this:

Param

Documentation of param shortcode.

Example param input:

1
{{< param description >}}

The rendered output looks like this:

Shortcodes are simple snippets inside your content files calling built-in or custom templates.

Ref

Documentation of ref shortcode.

Always use the {{% %}} notation when calling this shortcode.

Example ref input:

1
2
- [Built-in Shortcodes]({{% ref "/documentation/content-management/shortcodes/built-in" %}})
- [Extended Shortcodes]({{% ref "/documentation/content-management/shortcodes/extended" %}})

The rendered output looks like this:

The HTML looks like this:

1
2
3
4
<ul>
  <li><a href="http://example.org/documentation/content-management/shortcodes/built-in">Built-in Shortcodes</a></li>
  <li><a href="http://example.org/documentation/content-management/shortcodes/extended">Extended Shortcodes</a></li>
</ul>

Relref

Documentation of relref shortcode.

Always use the {{% %}} notation when calling this shortcode.

Example relref input:

1
2
- [Built-in Shortcodes]({{% relref "/documentation/content-management/shortcodes/built-in" %}})
- [Extended Shortcodes]({{% relref "/documentation/content-management/shortcodes/extended" %}})

The rendered output looks like this:

The HTML looks like this:

1
2
3
4
<ul>
  <li><a href="/documentation/content-management/shortcodes/built-in">Built-in Shortcodes</a></li>
  <li><a href="/documentation/content-management/shortcodes/extended">Extended Shortcodes</a></li>
</ul>

Twitter

Documentation of twitter shortcode

Example twitter input:

1
{{< twitter user="SanDiegoZoo" id="1453110110599868418" >}}

The rendered output looks like this:

Vimeo

Documentation of vimeo shortcode

Example vimeo input:

1
{{< vimeo 146022717 >}}

The rendered output looks like this:

Youtube

Documentation of youtube shortcode

Example youtube input:

1
{{< youtube 0RKpf3rK57I >}}

The rendered output looks like this:

Privacy Configuration

To learn how to configure your Hugo site to meet the new EU privacy regulation, see privacy protections.


Related Content

Buy me a coffee~
Lruihao AlipayAlipay
Lruihao WeChat PayWeChat Pay
0%