Slug

The slug is the part of the URL that identifies a page in a human-readable form. It is usually derived from the title of the page, but Front Matter CMS allows you to define a custom slug.

Default slug

The default slug is derived from the title of the page. It is automatically generated when you create a new page. The default slug is a URL-friendly version of the title, with all letters in lowercase, spaces replaced with hyphens, removes stop words, and special characters.

Example of the default slug
---
title: Just a sample page with a title
slug: sample-page-title
---
Info

The extension only supports English stopwords.

Important

If you do not define a slug in the content type, the slug will be derived from the frontMatter.taxonomy.slugTemplate setting. If the setting is not defined, the page name will be used as the slug.

Custom slug

You can define a custom slug for your pages and it can be defined on global level or per content type.

Global level

You can define a custom slug template for all pages in the frontMatter.taxonomy.slugTemplate setting. The template can contain placeholders that will be replaced with the actual values when creating a new page.

Example of the global slug template
{
  "frontMatter.taxonomy.slugTemplate": "{{year}}/{{month}}/{{title}}"
}
Info

When using the {{title}} placeholder in the slug template it will be automatically converted to lowercase and spaces will be replaced with hyphens. To have a SEO friendly URL, you can use the {{seoTitle}} placeholder instead.

Per content type

You can define a custom slug template for each content type in the frontMatter.taxonomy.contentTypes setting. Similar to the global slug template, the template can contain placeholders that will be replaced with the actual values when creating a new page.

Example of the content type slug template
{
  "frontMatter.taxonomy.contentTypes": [
    {
      "name": "post",
      "slugTemplate": "{{year}}/{{month}}/{{title}}",
      ...
    }
  ]
}

Additional settings

Prefix and suffix

You can also specify a prefix and suffix, which can be added to the slug if you want. Use the following settings to do this: frontMatter.taxonomy.slugPrefix and frontMatter.taxonomy.slugSuffix.

Example of the slug prefix and suffix
{
  "frontMatter.taxonomy.slugPrefix": "/",
  "frontMatter.taxonomy.slugSuffix": "/"
}
Example slug in combination with the prefix and suffix
---
title: Just a sample page with a title
slug: /sample-page-title/
---

By default, both prefix and suffix settings are not provided, which mean it would not add anything extra to the slug.

Align filename with slug

Another setting is to allow you to sync the filename with the generated slug. The setting you need to turn on enable for this is frontMatter.taxonomy.alignFilename.

Example of the align filename with slug
{
  "frontMatter.taxonomy.alignFilename": true
}

When you update the slug of the page, the filename will be automatically updated to match the slug.

Feedback/comments

Last updated on

Did you spot an issue in our documentation, or want to contribute? Edit this page on Github!

Ready to get started?

Special thanks to our backers & sponsors

run.events - Event Management PlatformNetlifyBEJS CommunityStruyf Consulting
Contributors
Dennis ZomaPatrick Kollitschmayumihara