Function: wp_unique_term_slug

wp_unique_term_slug( string $slug, object $term )

Will make slug unique, if it isn't already.

Shortcut: wuts

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

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.

The way this works is that if the taxonomy that the term belongs to is hierarchical and has a parent, it will append that parent to the $slug.

If that still doesn't return an unique slug, then it try to append a number until it finds a number that is truly unique.

The only purpose for $term is for appending a parent, if one exists.


Name Type(s) Default Value Description
$slug string

The string that will be tried for a unique slug.

$term object

The term object that the $slug will belong to.



Will return a true unique slug.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.