404 - Change title?

Is it possible to change the .Title that’s automatically set to “404 Page not found”, when generating a 404.html layout? I’m reusing my partials/header.html, which uses .Title in the <title></title>, and I would like it to be set to something else (not in English).


In my case, I use following code in my partials/header.html

{{ if eq .Title .Site.Title }}
  {{ .Title }}
{{ else }}
  {{ .Title }} &middot; {{ .Site.Title }}
{{ end }}

When I access not available page, the title uses latter. It displays “404 Page not found” and the site value I defined in config.toml so I think .Site.Title is the value what you want to use.

No, I want to localise .Title which seems hardcoded to “404 Page not found”.

As you say, it is hard coded. One of the other idea is using a template code like below in your partial/header.html

{{if eq .Url "404.html"}}
  Custom 404 Title String

It generates 404.html with “Custom 404 Title String”. Instead of using hard coded template string in partial/header.html, the custom param value defined in config.toml also can be used.

1 Like

That’s a workaround, not a proper solution :slight_smile:

It would be nice if this could be specified in a setting, or in the front matter of content/404.md.

Thanks @oscar_b. We didn’t think through localization completely. We really should have a better solution. Are there other places we need to address? I’d rather come up with a single solution for localization, rather than a bunch of disparate settings.

Not that I’ve found so far… The only other localisation issue I’ve seen is this: http://discuss.gohugo.io/t/url-encoding-error/115

{{if eq .URL "404.html"}}
  Custom 404 Title String

This is not working on Hugo 0.19 in header block :frowning:

So far this is how this works: