| 1 |
--- |
| 2 |
title: Lastmod |
| 3 |
description: Returns the last modification date of the given page. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: time.Time |
| 9 |
signatures: [PAGE.Lastmod] |
| 10 |
--- |
| 11 |
|
| 12 |
Set the last modification date in front matter: |
| 13 |
|
| 14 |
{{< code-toggle file=content/news/article-1.md fm=true >}} |
| 15 |
title = 'Article 1' |
| 16 |
lastmod = 2023-10-19T00:40:04-07:00 |
| 17 |
{{< /code-toggle >}} |
| 18 |
|
| 19 |
The last modification date is a [`time.Time`][] value. Format and localize the value with the [`time.Format`][] function, or use it with any of the [time methods][]. |
| 20 |
|
| 21 |
```go-html-template |
| 22 |
{{ .Lastmod | time.Format ":date_medium" }} → Oct 19, 2023 |
| 23 |
``` |
| 24 |
|
| 25 |
In the example above we explicitly set the last modification date in front matter. With Hugo's default configuration, the `Lastmod` method returns the front matter value. This behavior is configurable, allowing you to: |
| 26 |
|
| 27 |
- Set the last modification date to the Author Date of the last Git commit for that file. See [`GitInfo`][] for details. |
| 28 |
- Set fallback values if the last modification date is not defined in front matter. |
| 29 |
|
| 30 |
Learn more about [date configuration][]. |
| 31 |
|
| 32 |
[`GitInfo`]: /methods/page/gitinfo/ |
| 33 |
[`time.Format`]: /functions/time/format/ |
| 34 |
[date configuration]: /configuration/front-matter/#dates |
| 35 |
[time methods]: /methods/time/ |
| 36 |
[`time.Time`]: https://pkg.go.dev/time#Time |