Embed video in Hugo with a shortcode

Updated: November 25, 2026

Create a Hugo shortcode when several Markdown articles need the same kind of video player. A shortcode is a small call to a site template. In this example, an editor supplies a video ID and a title. The template builds the iframe and keeps its layout consistent across pages.

Separate the content and template

Copy the embed code from your Dembed video’s public page and find the ID after /embed/. For Hugo versions that use layouts/_shortcodes, create demovideo.html in that directory. Check your version’s template paths if you maintain an older project. Put the first block there. The template accepts the illustrated ID format and always uses the same domain.

{{ $id := .Get "id" | default "" }}
{{ $title := .Get "title" | default "" }}
{{ if and $title (findRE "^v_[0-9A-Za-z]{12}$" $id) }}
  <iframe src="https://dembed.cc/embed/{{ $id }}" title="{{ $title }}"
    style="display:block;width:100%;aspect-ratio:16 / 9;border:0"
    loading="lazy" allowfullscreen></iframe>
  <p><a href="https://dembed.cc/v/{{ $id }}">Watch the video</a></p>
{{ else }}
  {{ errorf "demovideo: provide a valid video ID and title (%s)" .Position }}
{{ end }}

Call it from Markdown

Add the second block to an article. Replace the example ID with the video you want to share and give it a descriptive title so the frame has a meaningful name. The example includes a direct link beside the frame. Translate the link label in the template if you maintain a multilingual site.

Keep the template under review in your repository. If you change its dimensions or provider domain, check an existing article as well as the new one. A shared template affects every call, and testing two different pages can catch an error a single preview would miss.

{{< demovideo id="v_Example12345" title="Assembly demonstration" >}}

Inspect the generated page

Run hugo server and open the article. Check the iframe’s ID in the HTML, test the layout on a phone, and open the direct link. Try two articles with different IDs to confirm that changing one does not affect the other. Repeat the test on the published site.

Frequently asked questions

The content calls the shortcode and the template generates the HTML. This workflow does not need raw HTML or inline shortcodes.

You might also like

Host your videos for free and earn from every view

Create your account in under a minute, upload your first video and start earning from day one.