By Digital Hub on April 14th, 2019
5min Read
Slug is the SEO friendly format of any text string. A slug is a text string contains alpha-numeric characters only, separated by “-“. Slugs play a significant role in web development because it’s easy to read, clean looking and SEO friendly. Search engines love clean slugs.
While working on a project I faced a requirement where slugs need to be created using the website links. So I added some extra lines of code in my existing create_slug() method and created a new function which is capable even to convert website URL’s into clean slug’s. This function will also add a “.html” extension at the end of the slug. Besides just making slugs from a string, this method is developed by keeping in mind to create slugs from website URL. The script will automatically remove the query string and will preserve the “/“, and “.” to convert them later into “–“.
Besides “.html” we can create our own extension.