October 7th, 2019

Creating an automated slug with contentful

  • #contentful
  • #slug
  • #seo
  • #blog

The problem

When writing an article or blog post you care about having an appealing title. Something with a lot of buzzwords in it, or trying to attract readers to read on. This sound very reasonable and fairy early to do. But there's more to the matter than just picking the correct title.
In terms of SEO and technicalities you want have a valid URL. If you have a title like "My super awesome article". The browser is going to replace the spaces with a strange token: %20. This is not very readable in your browser's address bar
https://www.your-site.com/my%20super%20awseome%20article

Introducing a slug

To solve this problem you can introduce a slug. You can be asking yourself what a slug is?
A slug is the part of a URL which identifies a particular page on a website in an easy to read form. In other words, it’s the part of the URL that explains the page’s content. For this article, for example, the URL is https://your-site.com/slug, and the slug simply is ‘slug’.
When writing a blog or article you want to replace the value of slug with the title of your article. You want to incorporate a bunch of key words to draw the visitor's attention. Next to attention, you also care about the readability of your article title in the url. A solution for this problem is to add dashes as a replacement for every space in your title. So the title can change from
https://www.your-site.com/my%20super%20awseome%20article
To
https://www.your-site.com/my-super-awseome-article
Now your URL became reader friendly and contains all the SEO keywords you wanted to include as well. You win on two fronts. But there comes another problem to the matter. Are you going to teach everyone who ever writes an article or blog post these technicalities? You probably want to automate the replacement of spaces in the title to dashes, without concerning your editorial people with technicalities. And you are right. Content driven people shouldn't care about how to format a valid URL. They should care about content and writing an appealing descriptive title.

Meet Contentful

When writing articles, people will probably do this using a Content Management System (CMS). The most known system is probably Wordpress. Recently though there is a change happening. The rise of headless content platforms is growing. Contentful is, in my honest opinion, one of the front runners in this business. But back to the business, how can you solve this slug problem?

Creating a slug in contentful

First you should create a new content model and name it whatever suits you best. Something like Article or BlogPost should fit.
slug-1.png
Slug-article.png
After creating the content model you can assign some attributes. Of course a good article needs a title, so create one. Next define a slug as well as shown below

Test the result

Eli Colpaert

By Eli Colpaert

Working at delaware, professional SAP C/4 enthusiast and quite passionate about new Open-Source technology.