Must slugs be unique?

In wp_unique_term_slug():

The $slug has to be unique global to every taxonomy, meaning that one taxonomy term can’t have a matching slug with another taxonomy term. Each slug has to be globally unique for every taxonomy.

In wp_unique_post_slug():

@param string $post_status no uniqueness checks are made if the post is still draft or pending […]

Attachment slugs must be unique across all types. […]

Page slugs must be unique within their own trees. Pages are in a separate namespace than posts so page slugs are allowed to overlap post slugs. […]

Post slugs must be unique across all posts […]

WordPress modifies post slugs to enforce uniqueness, if necessary, when a post’s status changes to publish or when Pages are moved among Page trees, so if you want to avoid that, it’s best to just try to write unique slugs yourself.

Unconfirmed, but I seem to remember:

  • WordPress sometimes increments slugs (hello-world-2) and sometimes truncates them (hello-worl !) to enforce uniqueness
  • You have to empty the Trash to make the slugs of Trashed posts available again.

Leave a Comment