Wordpress sometimes is plain limiting, and some of its logics I just don't get...

For example if I have two parent directories:

  • parent1
  • parent2

with subcategories:

  • parent1
    • sub
  • parent2
    • sub

I cannot have sub sub as slug or name... WordPress automatically appends what it thinks is best like sub-1 or sub-parent2. This is not very beautiful. And I consider this nothing short of a bug.


Short answer: No - it can't be done.

Long answer: Category slugs must be unique, regardless of parent. Although quite a few people like to call this a bug, it's actually by design. Basically, since categories can be moved around at will, the slugs must be unique. Sure, it's nested properly now, but if you decide at some point to do away with your hierarchy and move to a flat category structure, you'll have duplicate URLs (instead of cat1/slug, cat2/slug you'll have /slug and /slug). To avoid people unintentionally breaking their sites, they've enforced this restriction.

If you do hack the database to force duplicate slugs, it won't matter - if you navigate to a page that has a duplicate slug, it will load the first instance of that slug in the database no matter what. So if your first 'sub' is category ID 5 and your second 'sub' is category ID 20, and you force them to have the same slug, any time you go to category 20, it will load category 5.

The only time I've seen this successfully overridden is with WPML (so subdomain languages can have the same slug - en/slug, fr/slug, de/slug, etc), and they took MONTHS to make it work - even then it still has issues.

  • 1
    Six years on and this is still a relevant answer. :-) – Craig Jul 7 '18 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy