Create SEO-friendly URLs
Learn how to generate URL slugs from text elements to customize your URLs. The URL 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 text content element of your choice, unless you change the element's value manually. You can use the element only once in a content type.
Table of contents
Because the URL slug element can generate its value from any text element, 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.
Adding URL slug to content types
To add a URL slug to an existing content type:
- From the app menu, choose Content models.
- Open the Article content type for editing.
- Add the URL slug element to the content type.
- Type a name of the URL slug element. For example, you can label it "Page URL".
- Click Show configuration
- Select a text element 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 text element 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 dependent text element. Keep in mind that the limitation for the URL in web browsers is usually around 2,000 characters.
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 the URL slug and how many characters it has.
Autogenerated vs. manual values
By default, the URL slug value is autogenerated from the text element. The auto-generation follows two simple rules:
- All letters are changed to lowercase.
- Any sequence of special characters other than dashes (-) with be replaced by a dash to prevent problems when used in the URL.
You can also customize the URL slug value to suit your needs, which causes the element to switch to manual mode. As a result, the URL slug will no longer react to changes made to the dependent text element.
Multiple content items can have the same URL slug
Kentico Kontent doesn't check if the URL slug values in your content items are unique across your project. This means you can have multiple content items with the same URL slug value.
Getting items by their URL slugs
If you need to get content items by their URL slug values, check out how to retrieve localized content.
Deleting dependent text elements
When deleting a text element that is currently used to generate URL slug, there are two options depending on the location of the text element:
- In content types, the dependent text element can be deleted. After deleting the element, you'll be asked to choose a different text element before saving the changes. If you don’t have any text element in the current type, add a new text element.
- In content type snippets, the dependent text element cannot be deleted directly. First, in the content type, you need to choose a different text element to generate the URL slug. Then you can delete the text element in the content type snippet.
Element removal cannot be undone
This 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.