Skip to content

Modifying Permalinks

Posted on: Feb 15, 2021 by Stephanie Eckles
🍿 2 min. read

Examples of common ways to modify permalink structure.

Often permalinks are changed via front matter, but you may wish to apply permalink changes in a directory data file so that the change will apply to all content within a directory at once.

Remove Directory Prefix

As noted in the directory data file tips, you may wish for content contained in a directory to actually appear to live off of root:

permalink: "/{{ page.fileSlug }}/"

page is provided by 11ty and you can learn more about the page variable in the official docs

Add Date

The following will keep the existing structure based on directory location (provided by page.filePathStem), but prepend it with the content's date:

permalink: "/{{ }}/{{ page.filePathStem }}/"

Take a minute to learn about date handling in 11ty

You may want to use your post title for creating the permalink instead of the default of the file path/filename.

Conveniently, front matter data is available to permalink so you can actually use any front matter to modify the permalinks structure.

However - you need to use it alongside the slug filter to ensure it's URL-formatted.

permalink: "/{{ title | slug }}/"

If you tend to use code formatting or perhaps emojis in your titles (like I do) you may want to modify the slug filter.

Excluding and Moving Content

Permalinks can also be used to prevent content output, or change it's location.

View more quick tips