hugoDocs
hugoDocs copied to clipboard
content: Document how to customize the 404 page title
I'm confused on the current state of this. In up-to-date Hugo, how does one set a custom Title for the 404 page to override "404 Page not found" (e.g. for a non-English website)? This is not covered by the doc.
There is a dozen of threads about this on the support forum, mostly from 2017-2018, without a clear conclusion that does not involve ugly hacks.
https://github.com/gohugoio/hugoDocs/issues/585 is the closest I've found to in-depth information on the topic, but it was closed by the author for some reason.
Yeah, there are several ways to handle this.
Method 1
Make layouts/404.html a stand alone template (i.e., don't use base/block construct).
Method 2
Add a "title" block in baseof.html and override it in layouts/404.html.
Method 3
Don't use a 404 template. Create content pages instead.
```text
content/
├── 404.de.md
├── 404.md
├── _index.de.md
└── _index.md
```
content/404.md
```text
---
title: 404 (en)
url: 404.html
build:
list: never
---
```
content/404.de.md
```text
---
title: 404 (de)
url: 404.html
build:
list: never
---
```
published site
```text
public/
├── de/
│ ├── 404.html
│ └── index.html
├── en/
│ ├── 404.html
│ └── index.html
├── favicon.ico
└── index.html
```
Method 4
Don't use a 404 template. Create content pages instead, inside a dedicated directory.
```text
content/
├── error-pages/
│ ├── 403.de.md
│ ├── 403.md
│ ├── 404.de.md
│ └── 404.md
├── _index.de.md
└── _index.md
```
content/error-pages/404.md
```text
---
title: 404 (en)
url: 404.html
---
```
content/error-pages/404.de.md
```text
---
title: 404 (de)
url: 404.html
---
```
site configuration
```toml
[[cascade]]
[cascade.build]
list = 'never'
render = 'never'
[cascade.target]
path = '/error-pages'
[[cascade]]
[cascade.build]
list = 'never'
[cascade.target]
path = '/error-pages/*'
```
published site
```text
public/
├── de/
│ ├── 403.html
│ ├── 404.html
│ └── index.html
├── en/
│ ├── 403.html
│ ├── 404.html
│ └── index.html
├── favicon.ico
└── index.html
```
For a single error page I'd use option 3. If you need multiple error pages I'd use option 4.
We'll handle this as a guide in the new docs structure.
Thank you! I've managed to solve with a variation of 3. The key was to name the layout anything other than 404.