Embed YouTube video

Hello,
I want to know how to embed an online YouTube video. Basically I’m creating website with movies’ information. So I wanted their trailers. How to embed in post.md?
Thanks.

Hugo has a feature called shortcodes. With them you can write small scripts for repeated use in content files. There are also some built-in, for YouTube too. You can find a descrition about their usage here in the docs.

If your video link is:

https://www.youtube.com/watch?v=w7Ft2ymGmfc

{{< youtube w7Ft2ymGmfc >}}
8 Likes

Thanks guys.

Hi there, the above works fine for me, but there is a bug when the id has an underscore (_) like this video: https://www.youtube.com/watch?v=CMtN_LUpeLg
Any suggestions?

It works for me so can’t comment on how to fix it. Have you tried using the id shortcode parameter? Perhaps that might make a difference:

{{< youtube id="CMtN_LUpeLg" >}}
3 Likes

A post was split to a new topic: Please help me with GDPR and YouTube

Just in case this was not understood. Wrap the shortcode youtube id in quotes
It works well. Here is a real world sample with underscores. This post topic was well appreciated and helped me.

https://www.youtube.com/watch?v=Qy_h71a17Qo

{{< youtube "Qy_h71a17Qo" >}}