Slug from title

I’m trying to set the global permalink in a way it generates a title based slug. Currently it generates it based on the filename only.

If I set the _config.yml like this:

permalink: /:year/:month/:day/:title/

Then this:

2019-05-01-test1.md
---
layout: post
title: This is a test
---

Becomes this:

my-website.com/2019/05/01/test1/

And what I actually need is this:

my-website.com/2019/05/01/this-is-a-test/

I need it for SEO.

I tried to parse a Liquid variable on the front matter, like so:

---
layout: post
title: This is a test
slug: {{ page.title | slugify }}
---

But no luck here.

Any thoughts?

You can’t do it (that I know of) - seems like you should be able to, but you can’t, I think for backward compatability reasons:

You can either change the filename or just set the permalink in the front matter to whatever you want.

You can do this by setting a string value for the slug in the file’s front matter.

---
layout: post
title: This is a test
slug: this-is-a-test
---

I don’t think templating works in the front matter, hence why your solution didn’t work.

1 Like