Learn how to generate URL slugs from text elements to customize your URLs. TheURL slug element specifies an SEO-friendly text that you can use in the URLs of your content items. The element automatically generates its value based on the textcontent element of your choice, unless you change the element's value manually. You can use the element only once in a content type.
Because the URL slug element can generate its value from any textelement, you can use a different URL slug for each language variant of your content items.Let’s look at an example of using a URL slug in a content type.
Add a URL slug to content types
In Content model, open a content type for editing.
Add the URL slug element to the content type.
Type the name of the URL slug element. For example, you can label it Page URL.
Click in the element.
Select a textelement from the drop-down list to generate a URL slug.
The list shows text elements from the opened content type and also from any content type snippets already used in the type.
If there isn't any textelement to choose from, you need to add one first.
Click Save changes.
The URL slug's length is limited only by the maximum length of the controlling text element. Keep in mind that the limitation for the URL in web browsers is usually around 2,000 characters.
Reuse URL slug across languages
To keep items' URL slugs the same across your project languages, you have multiple options:
Set as non-localizable both the URL slug and the source element it's autogenerated from. All languages will use the default language value.
Set only the URL slug as non-localizable. The source element will be editable in non-default languages, but the URL slug will retain the value from the default language and be read-only in non-default languages.
Set only the source element as non-localizable. Initially, the URL slug will have the default language value across all languages, but it will be editable. That means you can localize it in non-default languages.
URL slug in content items
In content items, your content contributors will see the added URL slug element like this:In the bottom right corner of the URL slug (URL pattern in the image), you can see which text element generates theURL slug and how many characters it has.
Autogenerated vs. manual values
By default, the URL slug value is autogenerated from the selected text element. The autogeneration follows few rules to prevent problems in URLs:
All Latin letters are changed to lowercase.
Latin letters are stripped of diacritics (for example, characters ř, ł, ậ become r, l, a).
Characters that aren't Latin letters (for example, #, ., か, ლ) are replaced by a hyphen (-).
Groups of these characters between Latin letters are replaced by a single hyphen per group.
If the controlling text element contains only these characters, the slug remains empty.
An exception to this rule are some Cyrillic characters that get transcribed to their Latin counterparts.
You can also edit the URL slug value to suit your needs. Editing the autogenerated slug switches the element to the manual mode. As a result, the URL slug will no longer react to changes made to the controlling text element.
In need of unique URL slugs?
Kontent.ai doesn't check if a URL slug value is unique across your project. In other words, you can have multiple content items with the same URL slug. This may cause you issues when you use URL slugs to build URLs in your app. To ensure URL slugs of your items are unique, you have several options:
1. Create a middleware that listens to webhook notifications
When a content item is published or its workflow step changes, your middleware gets notified by a webhook and checks whether the item's URL slug is unique. If it's not, it then updates the URL slug value using the Management API to something unique. This approach requires you to maintain a database of your URL slugs the middleware can check against.
2. Create a custom element that checks the uniqueness of URL slugs
The Unique URL slug custom element generates a URL slug based on a text field value and checks whether the slug is unique. In case it discovers that the same URL slug already exists within the project, the element can append a postfix to make the new slug unique.
3. Don't rely on URL slugs only
Combine URL slugs with either a codename or a content item ID. This leaves you without the need to maintain a list of your URL slugs but requires you to change the structure of the URLs in your app.
When deleting the text element that is currently used to generate a URL slug, there are two options depending on the location of the text element:
In content types, the controlling textelement can be deleted. After deleting theelement, you'll be asked to select a different text element before saving the changes. If you don’t have any textelement in the current type, add a new text element.
In content type snippets, the controlling textelement cannot be deleted directly. First, in the content type, you need to select a different textelement to generate the URL slug. Then you can delete the text element in the content type snippet.
Add structure to your URLs with URL slugs for smooth navigation.
Element removal cannot be undoneThis action is irreversible. Removing an element from a content type or content type snippet removes the element across all content items based on that content type or snippet.