DEV Protip: Set the Slug of your posts

Siddharth - Jul 8 '21 - - Dev Community

TL;DR

When creating a post, set it's title to the slug you like and then publish it. You can change the title to the desired one later.


Check out the slug of this post ^ up there. Do you see it?

The slug should have been dev-protip-set-the-slug-of-your-posts or something like that. But instead, it is dev-tip-set-slug, which is much more readable. Here, I'll show you how to set the slugs of any post.

Note: This won't work for published posts. You have to do this when you create a new post or edit a draft.

  1. Create a Post

    create-post

    Click on that button at the top right
  2. Set the title of the post as the slug

    set-slug

    Choose a small, appropriate slug
  3. Write your content and publish the post

    You can continue writing your post's contents. Just make sure to not change the title. Once you finish, you can publish the post.

    Now, the slug will be generated from the post title.

    view-slug

  4. Fix the title

    Now, you edit the post and set the proper title, then you can click Save Changes. The trick here is that if you edit the title, the slug will not be recalculated.

  5. Done!

    You can continue making changes to the title, body and tags, but the slug will never change. This is supposed to be a bug, but it can be sort of useful.

    If you want, you can view the post which I showed you in this post here

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .