# \[SOLVED\] Unable to override permalink URL with slug in frontmatter

**URL:** <https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539>\
**Category:** support\
**Created:** [September 27, 2017, 1:51pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539 "2017-09-27T13:51:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanorth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanorth/32/1177_2.png) [@alanorth](https://discourse.gohugo.io/u/alanorth)\
**Post date:** [September 27, 2017, 1:51pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/1 "2017-09-27T13:51:32Z")

</div>

According to the documentation it should be possible to [override the URL](https://gohugo.io/content-management/urls/#override-urls-with-front-matter) with `slug` or `url` in frontmatter but it doesn’t seem to work for me. I would like post permalinks like `2017-09` by default, but want to be able to override this on specific posts. Instead I get two posts with the same permalink: `2017-09`.

I have observed this happening on at least Hugo v0.27.1 and v0.29. This simple setup can reproduce it:

_config.toml_:

```auto
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "hyde"

[permalinks]
  post = "/:year-:month/"

```

_content/post/test1.md_:

```auto
---
title: "Test Post 1"
date: 2017-09-27T16:29:39+03:00
---

Testing a post.

```

_content/post/test2.md_:

```auto
---
title: "Test Post 2"
date: 2017-09-27T16:31:16+03:00
slug: testing-page
---

Testing another post.

```

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [September 27, 2017, 2:15pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/2 "2017-09-27T14:15:24Z")

</div>

I’m using slug on different pages and it works (latest Hugo Release). Make sure that `slug` in Front Matter is not after a list or and array (like `[menu.main]` or `[[products]]`.

I have the following order:

```auto
+++
title = "Development Resources"
date = "2017-07-12T12:39:57+02:00"
description = "This description comes from resources.md"
draft = false
series = ["Resources"]
categories = ["Docs"]
tags = []
bodyclass = "resources"
slug = "/useful-resources/"

[menu.main]
name = "Sources"
weight = 35
+++

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![alanorth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanorth/32/1177_2.png) [@alanorth](https://discourse.gohugo.io/u/alanorth)\
**Post date:** [September 27, 2017, 2:22pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/3 "2017-09-27T14:22:13Z")

</div>

@Leo_Merkel my example here is enough to reproduce the issue—there are no lists or arrays in the frontmatter. Just curious, what do you have as the `permalinks` setting in your site configuration?

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [September 27, 2017, 2:26pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/4 "2017-09-27T14:26:35Z")

</div>

```auto
[permalinks]
post = "/:year/:month/:title/"
page = "/:slug/"

```

---

<div class="post-metadata">

**Author:** ![alanorth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanorth/32/1177_2.png) [@alanorth](https://discourse.gohugo.io/u/alanorth)\
**Post date:** [September 27, 2017, 3:22pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/5 "2017-09-27T15:22:23Z")

</div>

Thanks, @Leo_Merkel. Is the frontmatter snippet above a top-level page or a post? I’m guessing the difference here is you’re creating top-level pages, not posts. In my example all my content are posts, and no permalink setting makes any difference.

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [September 27, 2017, 3:26pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/6 "2017-09-27T15:26:05Z")

</div>

It’s a top level page. But it works as well on posts. I have them in a directory `articles` and use the following Front Matter for slug (sorry, it’s in German):

```auto
+++
title = "Beitrag 1"
description = "Zusammenfassung des Beitrags 1."
date = "2016-04-13T22:07:07+02:00"
type = "post"
slug = "erster beitrag"

categories = ["Leos Seite"]
tags = ["eins", "zwei"]

bodyclass = "beitrag"
+++

```

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [September 27, 2017, 7:15pm UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/7 "2017-09-27T19:15:27Z")

</div>

Eye-balling it, it looks like you are specifically telling Hugo to skip the `slug` parameter. A “slug” is the portion of the URL that refers to a specific piece of content. The defaults make it so it works as expected for most folks, playing with `title` and working in common permalink patterns.

But yours says to just make a year and a month. If you have `:title` or `:slug` somewhere in the permalink, it should generate as expected.

---

<div class="post-metadata">

**Author:** ![alanorth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanorth/32/1177_2.png) [@alanorth](https://discourse.gohugo.io/u/alanorth)\
**Post date:** [September 28, 2017, 5:46am UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/8 "2017-09-28T05:46:38Z")

</div>

> [@maiki](#):
>
> Eye-balling it, it looks like you are specifically telling Hugo to skip the slug parameter. A “slug” is the portion of the URL that refers to a specific piece of content. The defaults make it so it works as expected for most folks, playing with title and working in common permalink patterns.

Hmm, that’s not how I understand the documentation regarding [URL management](https://gohugo.io/content-management/urls). We should be able to override the slug in frontmatter, regardless of whether the site’s configuration uses `:slug` in the `[permalinks]` setting.

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [September 28, 2017, 7:15am UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/9 "2017-09-28T07:15:33Z")

</div>

> [@alanorth](#):
>
> We should be able to override the slug in frontmatter, regardless of whether the site’s configuration uses :slug in the [permalinks] setting.

I may misunderstand your issue. Do you have a use for the `slug`, aside from the permalink, and it isn’t working properly?

I think you may be thinking of `url` after all. The slug changes how the `:slug` shows up in a permalink. It overrides the `:title`. `url` in front matter, however, changes the complete URL, relative to the `baseurl`.

Have you tried adding something like this to a post’s front matter?

```toml
url = "test/out/url"

```

It should make whichever post render at `example.com/test/out/url/`.

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [September 28, 2017, 7:30am UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/10 "2017-09-28T07:30:56Z")

</div>

I found a place in the docs where permalinks are explained in more detail, maybe we ought to link to it from the URL management doc: [https://gohugo.io/content-management/organization/#path-breakdown-in-hugo](https://gohugo.io/content-management/organization/#path-breakdown-in-hugo)

That shows where and how `url` and `slug` are used in generating a path. 🙂

---

<div class="post-metadata">

**Author:** ![alanorth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/alanorth/32/1177_2.png) [@alanorth](https://discourse.gohugo.io/u/alanorth)\
**Post date:** [September 28, 2017, 7:33am UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/11 "2017-09-28T07:33:31Z")

</div>

You’re right, @maiki. I was misunderstanding the use of `slug` in frontmatter and using `url` does indeed achieve what I want. I was just coming here to say that the [Content Organization](https://gohugo.io/content-management/organization/#path-breakdown-in-hugo) page of the docs explains this a little better—although the ASCII flowcharts aren’t very readable if you don’t realize the code blocks expand on hover. 😝

Marking as `[SOLVED]`.

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [September 28, 2017, 7:35am UTC](https://discourse.gohugo.io/t/solved-unable-to-override-permalink-url-with-slug-in-frontmatter/8539/12 "2017-09-28T07:35:08Z")

</div>

Feel free to make changes to the docs! They get better as we figure out the gaps, and folks contribute their knowledge. 🙂
