Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Your blog post title is not a URL slug

Your blog post title is not a URL slug Every CMS turns your title into a URL automatically, and most of them do a lazy job of it. The slug they generate is usually too long, full of stop words nobody searches for, and s

Your blog post title is not a URL slug

Every CMS turns your title into a URL automatically, and most of them do a lazy job of it. The slug they generate is usually too long, full of stop words nobody searches for, and sometimes broken in ways you only notice when the link gets shared. A slug is a small thing, but it is the part of your URL that Google reads, that people read, and that never changes once the page is live.

Here is the whole job, in plain JavaScript:

function slugify(title) {
  return title
    .normalize('NFKD')                    // split Γ© into e + accent
    .replace(/[\u0300-\u036f]/g, '')      // drop the accent marks
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, '-')          // punctuation and spaces become one hyphen
    .replace(/^-+|-+$/g, '');             // trim leading and trailing hyphens
}

That is the whole engine. Five lines, no library, no server. Run it in your browser console right now.

The accent trap

Take a food blog title: "Café Crème Brûlée: 10 Tips & Tricks for 2026!"

A lazy slug keeps the accents, and the URL becomes a percent-encoded mess that nobody can read or type. The NFKD step fixes it:

  • Input: CafΓ© CrΓ¨me BrΓ»lΓ©e: 10 Tips & Tricks for 2026!
  • Output: cafe-creme-brulee-10-tips-tricks-2026

The accents are gone, the meaning survived, and the URL is readable in any browser, any email client, any chat app. The normalize('NFKD') call is the one line most hand-rolled slug functions forget, and it is the difference between a clean URL and one full of %C3%A9.

The stop-word tax

Now take a normal English title: "How to Choose the Right Running Shoes for Flat Feet".

The naive slug is how-to-choose-the-right-running-shoes-for-flat-feet. Fifty-one characters, and six of the words, how, to, the, for, add nothing. Nobody searches for "how to choose the right running shoes for flat feet" as a URL, and Google stopped needing stop words in URLs years ago.

Remove them and you get how-choose-right-running-shoes-flat-feet. Forty characters, every word carrying meaning. Shorter slugs are easier to share, easier to remember, and they still read fine when someone sees the bare link. The one rule: never remove a word that changes the meaning. "The" is safe to drop. "Not" is not.

The apostrophe nobody notices

One more: "The 2026 Guide to Men's Waterproof Hiking Boots" becomes 2026-guide-men-s-waterproof-hiking-boots. See it? men-s. The apostrophe turned into a hyphen, and now your slug has a word that does not exist. A good slug function strips apostrophes before it converts punctuation to hyphens, or the possessive quietly corrupts the URL. It is a tiny bug, and it ships on real sites every day.

Why this runs in your browser

A slug generator has no reason to send your titles anywhere. Your unpublished post titles are your business, so the honest version does everything client-side: the transliteration, the stop-word list, the bulk mode that turns a whole column of titles into slugs at once, and the CSV export for a Shopify or WordPress import. Nothing leaves your device.

If you want the slug without writing the function yourself, I built a free tool that does exactly this: live slugs as you type, separator and stop-word options, a length check that warns past 75 characters, and bulk mode that keeps repeats unique. Try it here: URL Slug Generator.

Your title is not your slug. Five lines of JavaScript stand between the two, and once you see what the naive version does to an apostrophe, you will never trust the auto-generated one again.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.