Slug deduction failing?

I have some pages that have a slug that is different from the page title. The slug is generated from the page title instead of the file path. Can someone explain why, and how I can prevent this.

Example:

Content file:

content/posts/2024/07/hello-world/index.md

---
title: Hallo Wereld
date: "2024-07-20T17:17:17+02:00"
# etc.
---
Some content...

My permalink structure is:

[permalinks]
  posts = "/:year/:month/:day/:slug/"

When browsing the site, the slug becomes:

http://localhost:1313/2024/07/20/hallo-wereld/

I could force a slug with the slug: key, but I would rather prefer that the path name is used. Thats also how it is listed in the documentation:

By default, when Hugo renders a page, the resulting URL matches the file path within the content directory.

and (emphasis mine)

Set the slug in front matter to override the last segment of the path. The slug value does not affect section pages.

Thanks in advance for any suggestions.

https://gohugo.io/content-management/urls/#tokens

:slug

The slug as defined in front matter, else the title as defined in front matter, else the automatic title. Hugo generates titles automatically for section, taxonomy, and term pages that are not backed by a file.

1 Like

Thanks:

I did some additional reading. The :slugorfilename does what I want. Never knew of it’s existence.

:slugorfilename
The slug as defined in front matter, else the content’s file name without extension, applicable to the page page kind.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.