| 1 |
--- |
| 2 |
title: Embedded partial templates |
| 3 |
description: Hugo provides embedded partial templates for common use cases. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
weight: 180 |
| 7 |
aliases: [/templates/internal] |
| 8 |
--- |
| 9 |
|
| 10 |
## Disqus |
| 11 |
|
| 12 |
> [!NOTE] |
| 13 |
> To override Hugo's embedded Disqus template, copy the [source code](<{{% eturl disqus %}}>) to a file with the same name in the `layouts/_partials` directory, then call it from your templates using the [`partial`][] function: |
| 14 |
> |
| 15 |
> `{{ partial "disqus.html" . }}` |
| 16 |
|
| 17 |
Hugo includes an embedded template for [Disqus][], a commenting system for both static and dynamic websites. To use this template, you must first obtain a Disqus shortname by [signing up][] for the free service. |
| 18 |
|
| 19 |
To include the embedded template: |
| 20 |
|
| 21 |
```go-html-template |
| 22 |
{{ partial "disqus.html" . }} |
| 23 |
``` |
| 24 |
|
| 25 |
### Configuration {#configuration-disqus} |
| 26 |
|
| 27 |
To use Hugo's Disqus template, first set up a single configuration value: |
| 28 |
|
| 29 |
{{< code-toggle file=hugo >}} |
| 30 |
[services.disqus] |
| 31 |
shortname = 'your-disqus-shortname' |
| 32 |
{{</ code-toggle >}} |
| 33 |
|
| 34 |
You can also set the following in the [front matter][] for a given page: |
| 35 |
|
| 36 |
`disqus_identifier` |
| 37 |
: (`string`) A unique identifier for the page's discussion thread. Set this to preserve comment threads across URL changes. |
| 38 |
|
| 39 |
`disqus_title` |
| 40 |
: (`string`) The title of the discussion thread. |
| 41 |
|
| 42 |
`disqus_url` |
| 43 |
: (`string`) The canonical URL for the discussion thread. Use this to override the URL Disqus uses to identify the thread, for example when the same content is served at multiple URLs. |
| 44 |
|
| 45 |
{{< code-toggle file=content/blog/my-post.md fm=true >}} |
| 46 |
[params] |
| 47 |
disqus_identifier = 'unique-identifier' |
| 48 |
disqus_title = 'Post title' |
| 49 |
disqus_url = 'https://example.org/blog/my-post/' |
| 50 |
{{</ code-toggle >}} |
| 51 |
|
| 52 |
> [!NOTE] |
| 53 |
> When previewing your site locally, Hugo replaces the Disqus widget with the message "Disqus comments not available by default when the website is previewed locally." |
| 54 |
|
| 55 |
### Privacy {#privacy-disqus} |
| 56 |
|
| 57 |
Adjust the relevant privacy settings in your project configuration. |
| 58 |
|
| 59 |
{{< code-toggle config=privacy.disqus />}} |
| 60 |
|
| 61 |
`disable` |
| 62 |
: (`bool`) Whether to disable the template. Default is `false`. |
| 63 |
|
| 64 |
## Google Analytics |
| 65 |
|
| 66 |
> [!NOTE] |
| 67 |
> To override Hugo's embedded Google Analytics template, copy the [source code](<{{% eturl google_analytics %}}>) to a file with the same name in the `layouts/_partials` directory, then call it from your templates using the [`partial`][] function: |
| 68 |
> |
| 69 |
> `{{ partial "google_analytics.html" . }}` |
| 70 |
|
| 71 |
Hugo includes an embedded template for [Google Analytics 4][]. |
| 72 |
|
| 73 |
To include the embedded template: |
| 74 |
|
| 75 |
```go-html-template |
| 76 |
{{ partial "google_analytics.html" . }} |
| 77 |
``` |
| 78 |
|
| 79 |
### Configuration {#configuration-google-analytics} |
| 80 |
|
| 81 |
Provide your tracking ID in your configuration file: |
| 82 |
|
| 83 |
{{< code-toggle file=hugo >}} |
| 84 |
[services.googleAnalytics] |
| 85 |
id = 'G-MEASUREMENT_ID' |
| 86 |
{{</ code-toggle >}} |
| 87 |
|
| 88 |
> [!NOTE] |
| 89 |
> If the configured ID begins with `ua-` (case-insensitive), Hugo logs a warning and renders nothing. Google Universal Analytics (UA) was replaced by Google Analytics 4 (GA4) effective 1 July 2023. Create a GA4 property and data stream, then update your project configuration with the new measurement ID. |
| 90 |
|
| 91 |
### Privacy {#privacy-google-analytics} |
| 92 |
|
| 93 |
Adjust the relevant privacy settings in your project configuration. |
| 94 |
|
| 95 |
{{< code-toggle config=privacy.googleAnalytics />}} |
| 96 |
|
| 97 |
`disable` |
| 98 |
: (`bool`) Whether to disable the template. Default is `false`. |
| 99 |
|
| 100 |
`respectDoNotTrack` |
| 101 |
: (`bool`) Whether to respect the browser's "do not track" setting. Default is `true`. |
| 102 |
|
| 103 |
## Open Graph |
| 104 |
|
| 105 |
> [!NOTE] |
| 106 |
> To override Hugo's embedded Open Graph template, copy the [source code](<{{% eturl opengraph %}}>) to a file with the same name in the `layouts/_partials` directory, then call it from your templates using the [`partial`][] function: |
| 107 |
> |
| 108 |
> `{{ partial "opengraph.html" . }}` |
| 109 |
|
| 110 |
Hugo includes an embedded template for the [Open Graph protocol][]. This metadata transforms your pages into rich objects when shared across major social media and messaging platforms. |
| 111 |
|
| 112 |
To include the embedded template: |
| 113 |
|
| 114 |
```go-html-template |
| 115 |
{{ partial "opengraph.html" . }} |
| 116 |
``` |
| 117 |
|
| 118 |
### Configuration {#configuration-open-graph} |
| 119 |
|
| 120 |
Hugo's Open Graph template is configured using a mix of configuration settings and [front matter][] values on individual pages. |
| 121 |
|
| 122 |
{{< code-toggle file=hugo >}} |
| 123 |
title = 'My cool site' |
| 124 |
[params] |
| 125 |
description = 'Text about my cool site' |
| 126 |
images = ['site-feature-image.jpg'] |
| 127 |
[params.social] |
| 128 |
facebook_app_id = '12345678' |
| 129 |
[taxonomies] |
| 130 |
series = 'series' |
| 131 |
{{</ code-toggle >}} |
| 132 |
|
| 133 |
{{< code-toggle file=content/blog/my-post.md fm=true >}} |
| 134 |
title = 'Post title' |
| 135 |
description = 'Text about this post' |
| 136 |
date = 2024-03-08T08:18:11-08:00 |
| 137 |
images = ["post-cover.png"] |
| 138 |
audio = [] |
| 139 |
videos = [] |
| 140 |
series = [] |
| 141 |
tags = [] |
| 142 |
locale = 'en-US' |
| 143 |
{{</ code-toggle >}} |
| 144 |
|
| 145 |
### Metadata {#metadata-open-graph} |
| 146 |
|
| 147 |
Hugo emits the following metadata: |
| 148 |
|
| 149 |
`og:url` |
| 150 |
: The page permalink. |
| 151 |
|
| 152 |
`og:site_name` |
| 153 |
: The site title, falling back to the site configuration's `params.title` value. |
| 154 |
|
| 155 |
`og:title` |
| 156 |
: The page title, falling back to the site title, then the site configuration's `params.title` value. |
| 157 |
|
| 158 |
`og:description` |
| 159 |
: The page description, falling back to the page summary, then the site configuration's `params.description` value. |
| 160 |
|
| 161 |
`og:locale` |
| 162 |
: The `locale` front matter value, falling back to the site language's `locale`; hyphens are replaced with underscores (e.g. `en-US` → `en_US`). |
| 163 |
|
| 164 |
`og:type` |
| 165 |
: The value is `article` for pages and `website` for list and home pages. |
| 166 |
|
| 167 |
For article pages, Hugo also emits: |
| 168 |
|
| 169 |
`article:section` |
| 170 |
: The page's top-level section. |
| 171 |
|
| 172 |
`article:published_time` |
| 173 |
: The page's publish date. |
| 174 |
|
| 175 |
`article:modified_time` |
| 176 |
: The page's last modified date. |
| 177 |
|
| 178 |
`article:tag` |
| 179 |
: The first 6 tags. |
| 180 |
|
| 181 |
For image metadata, Hugo emits up to 6 `og:image` tags. |
| 182 |
|
| 183 |
{{% include "/_common/embedded-get-page-images.md" %}} |
| 184 |
|
| 185 |
`audio` and `videos` are `[]string` front matter parameters. Hugo emits up to 6 `og:audio` and `og:video` tags, passing each value through `absURL`, which converts relative paths to absolute URLs. Unlike `images`, Hugo does not search page resources or global resources for these values. |
| 186 |
|
| 187 |
The `series` taxonomy is used to populate `og:see_also` metadata. Hugo emits up to 7 `og:see_also` tags using the first 7 pages in the same series as the current page, excluding the current page itself. |
| 188 |
|
| 189 |
For Facebook metadata, if the site configuration's `params.social.facebook_app_id` value is set, Hugo emits `fb:app_id`. Otherwise, if the site configuration's `params.social.facebook_admin` value is set, Hugo emits `fb:admins`. |
| 190 |
|
| 191 |
## Pagination |
| 192 |
|
| 193 |
> [!NOTE] |
| 194 |
> To override Hugo's embedded pagination template, copy the [source code](<{{% eturl pagination %}}>) to a file with the same name in the `layouts/_partials` directory, then call it from your templates using the [`partial`][] function: |
| 195 |
> |
| 196 |
> `{{ partial "pagination.html" . }}` |
| 197 |
|
| 198 |
Hugo includes an embedded template for rendering navigation links between pagers. To include the embedded template: |
| 199 |
|
| 200 |
```go-html-template |
| 201 |
{{ partial "pagination.html" . }} |
| 202 |
``` |
| 203 |
|
| 204 |
The embedded pagination template has two formats: `default` and `terse`. The `terse` format has fewer controls and page slots, consuming less space when styled as a horizontal list. See [pagination][] for details. |
| 205 |
|
| 206 |
## Schema |
| 207 |
|
| 208 |
> [!NOTE] |
| 209 |
> To override Hugo's embedded Schema template, copy the [source code](<{{% eturl schema %}}>) to a file with the same name in the `layouts/_partials` directory, then call it from your templates using the [`partial`][] function: |
| 210 |
> |
| 211 |
> `{{ partial "schema.html" . }}` |
| 212 |
|
| 213 |
Hugo includes an embedded template to render [microdata][] `meta` elements within the `head` element of your templates. |
| 214 |
|
| 215 |
To include the embedded template: |
| 216 |
|
| 217 |
```go-html-template |
| 218 |
{{ partial "schema.html" . }} |
| 219 |
``` |
| 220 |
|
| 221 |
### Configuration {#configuration-schema} |
| 222 |
|
| 223 |
Hugo's Schema template uses a mix of page data and [front matter][] values on individual pages. |
| 224 |
|
| 225 |
{{< code-toggle file=hugo >}} |
| 226 |
title = 'My cool site' |
| 227 |
[params] |
| 228 |
description = 'Text about my cool site' |
| 229 |
{{</ code-toggle >}} |
| 230 |
|
| 231 |
{{< code-toggle file=content/blog/my-post.md fm=true >}} |
| 232 |
title = 'Post title' |
| 233 |
description = 'Text about this post' |
| 234 |
date = 2024-03-08T08:18:11-08:00 |
| 235 |
lastmod = 2024-03-09T12:00:00-08:00 |
| 236 |
images = ['post-cover.png'] |
| 237 |
keywords = ['ssg', 'hugo'] |
| 238 |
{{</ code-toggle >}} |
| 239 |
|
| 240 |
### Metadata {#metadata-schema} |
| 241 |
|
| 242 |
Hugo emits the following microdata: |
| 243 |
|
| 244 |
`name` |
| 245 |
: The page title, falling back to the site title. |
| 246 |
|
| 247 |
`description` |
| 248 |
: The page description, falling back to the page summary, then the site configuration's `params.description` value. |
| 249 |
|
| 250 |
`datePublished` |
| 251 |
: The page's publish date. |
| 252 |
|
| 253 |
`dateModified` |
| 254 |
: The page's last modified date. |
| 255 |
|
| 256 |
`wordCount` |
| 257 |
: The page's word count. |
| 258 |
|
| 259 |
For image metadata, Hugo emits up to 6 `image` tags. |
| 260 |
|
| 261 |
{{% include "/_common/embedded-get-page-images.md" %}} |
| 262 |
|
| 263 |
For keyword metadata, Hugo uses the following order of precedence: |
| 264 |
|
| 265 |
1. Titles of `keywords` taxonomy terms, if `keywords` is defined as a taxonomy |
| 266 |
1. The `keywords` front matter value, if `keywords` is not a taxonomy |
| 267 |
1. Titles of `tags` taxonomy terms |
| 268 |
1. Titles of all taxonomy terms |
| 269 |
|
| 270 |
## X (Twitter) Cards |
| 271 |
|
| 272 |
> [!NOTE] |
| 273 |
> To override Hugo's embedded Twitter Cards template, copy the [source code](<{{% eturl twitter_cards %}}>) to a file with the same name in the `layouts/_partials` directory, then call it from your templates using the [`partial`][] function: |
| 274 |
> |
| 275 |
> `{{ partial "twitter_cards.html" . }}` |
| 276 |
|
| 277 |
Hugo includes an embedded template for [X (Twitter) Cards][], metadata used to attach rich media to Tweets linking to your site. |
| 278 |
|
| 279 |
To include the embedded template: |
| 280 |
|
| 281 |
```go-html-template |
| 282 |
{{ partial "twitter_cards.html" . }} |
| 283 |
``` |
| 284 |
|
| 285 |
### Configuration {#configuration-x-cards} |
| 286 |
|
| 287 |
Hugo's X (Twitter) Card template is configured using a mix of configuration settings and [front matter][] values on individual pages. |
| 288 |
|
| 289 |
{{< code-toggle file=hugo >}} |
| 290 |
[params] |
| 291 |
description = 'Text about my cool site' |
| 292 |
images = ["site-feature-image.jpg"] |
| 293 |
[params.social] |
| 294 |
twitter = 'GoHugoIO' |
| 295 |
{{</ code-toggle >}} |
| 296 |
|
| 297 |
{{< code-toggle file=content/blog/my-post.md fm=true >}} |
| 298 |
title = 'Post title' |
| 299 |
description = 'Text about this post' |
| 300 |
images = ["post-cover.png"] |
| 301 |
{{</ code-toggle >}} |
| 302 |
|
| 303 |
### Metadata {#metadata-x-cards} |
| 304 |
|
| 305 |
If an image is found, Hugo sets `twitter:card` to `summary_large_image` and emits a `twitter:image` tag using the first image found. If no image is found, Hugo sets `twitter:card` to `summary` and omits the image tag. |
| 306 |
|
| 307 |
{{% include "/_common/embedded-get-page-images.md" %}} |
| 308 |
|
| 309 |
Hugo also emits the following metadata: |
| 310 |
|
| 311 |
`twitter:title` |
| 312 |
: The page title, falling back to the site title, then the site configuration's `params.title` value. |
| 313 |
|
| 314 |
`twitter:description` |
| 315 |
: The page description, falling back to the page summary, then the site configuration's `params.description` value. |
| 316 |
|
| 317 |
`twitter:site` |
| 318 |
: The site configuration's `params.social.twitter` value. The `@` prefix is added automatically if not already present. For example, with `twitter = 'GoHugoIO'` in your configuration, Hugo renders: |
| 319 |
|
| 320 |
```html |
| 321 |
<meta name="twitter:site" content="@GoHugoIO"/> |
| 322 |
``` |
| 323 |
|
| 324 |
[Disqus]: https://disqus.com |
| 325 |
[Google Analytics 4]: https://support.google.com/analytics/answer/10089681 |
| 326 |
[Open Graph protocol]: https://ogp.me/ |
| 327 |
[X (Twitter) Cards]: https://developer.x.com/en/docs/twitter-for-websites/cards/overview/abouts-cards |
| 328 |
[`partial`]: /functions/partials/include/ |
| 329 |
[front matter]: /content-management/front-matter/ |
| 330 |
[microdata]: https://html.spec.whatwg.org/multipage/microdata.html#microdata |
| 331 |
[pagination]: /templates/pagination/ |
| 332 |
[signing up]: https://disqus.com/profile/signup/ |