| 1 |
--- |
| 2 |
title: YouTube shortcode |
| 3 |
linkTitle: YouTube |
| 4 |
description: Embed a YouTube video in your content using the youtube shortcode. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
> [!NOTE] |
| 10 |
> To override Hugo's embedded `youtube` shortcode, copy the [source code][] to a file with the same name in the `layouts/_shortcodes` directory. |
| 11 |
|
| 12 |
## Example |
| 13 |
|
| 14 |
To display a YouTube video with this URL: |
| 15 |
|
| 16 |
```text |
| 17 |
https://www.youtube.com/watch?v=0RKpf3rK57I |
| 18 |
``` |
| 19 |
|
| 20 |
Include this in your Markdown: |
| 21 |
|
| 22 |
```md |
| 23 |
{{</* youtube 0RKpf3rK57I */>}} |
| 24 |
``` |
| 25 |
|
| 26 |
Hugo renders this to: |
| 27 |
|
| 28 |
{{< youtube 0RKpf3rK57I >}} |
| 29 |
|
| 30 |
## Arguments |
| 31 |
|
| 32 |
`id` |
| 33 |
: (`string`) The video `id`. Optional if the `id` is the first and only positional argument. |
| 34 |
|
| 35 |
`allowFullScreen` |
| 36 |
: (`bool`) Whether the `iframe` element can activate full screen mode. Default is `true`. |
| 37 |
|
| 38 |
`autoplay` |
| 39 |
: (`bool`) Whether to automatically play the video. Forces `mute` to `true`. Default is `false`. |
| 40 |
|
| 41 |
`class` |
| 42 |
: (`string`) The `class` attribute of the wrapping `div` element. When specified, removes the `style` attributes from the `iframe` element and its wrapping `div` element. |
| 43 |
|
| 44 |
`controls` |
| 45 |
: (`bool`) Whether to display the video controls. Default is `true`. |
| 46 |
|
| 47 |
`end` |
| 48 |
: (`int`) The time, measured in seconds from the start of the video, when the player should stop playing the video. |
| 49 |
|
| 50 |
`loading` |
| 51 |
: (`string`) The loading attribute of the `iframe` element, either `eager` or `lazy`. Default is `eager`. |
| 52 |
|
| 53 |
`loop` |
| 54 |
: (`bool`) Whether to indefinitely repeat the video. Ignores the `start` and `end` arguments after the first play. Default is `false`. |
| 55 |
|
| 56 |
`mute` |
| 57 |
: (`bool`) Whether to mute the video. Always `true` when `autoplay` is `true`. Default is `false`. |
| 58 |
|
| 59 |
`start` |
| 60 |
: (`int`) The time, measured in seconds from the start of the video, when the player should start playing the video. |
| 61 |
|
| 62 |
`title` |
| 63 |
: (`string`) The `title` attribute of the `iframe` element. Defaults to "YouTube video". |
| 64 |
|
| 65 |
Here's an example using some of the available arguments: |
| 66 |
|
| 67 |
```md |
| 68 |
{{</* youtube id=0RKpf3rK57I start=30 end=60 loading=lazy */>}} |
| 69 |
``` |
| 70 |
|
| 71 |
## Privacy |
| 72 |
|
| 73 |
Adjust the relevant privacy settings in your project configuration. |
| 74 |
|
| 75 |
{{< code-toggle config=privacy.youTube />}} |
| 76 |
|
| 77 |
`disable` |
| 78 |
: (`bool`) Whether to disable the shortcode. Default is `false`. |
| 79 |
|
| 80 |
`privacyEnhanced` |
| 81 |
: (`bool`) Whether to block YouTube from storing information about visitors on your website unless the user plays the embedded video. Default is `false`. |
| 82 |
|
| 83 |
[source code]: <{{% eturl youtube %}}> |