1. Home
  2. Docs
  3. Filters & Hooks
  4. How to limit the number of words in WordPress permalinks or slugs?

How to limit the number of words in WordPress permalinks or slugs?

Permalink Manager allows to programmatically limit the number of words in each slug that is the part of the custom permalink.

For example:

http://example.com/a-very-long-slug-with-seven-words/slug-with-exactly-five-words/another-pretty-long-sentence-that-should-be-shorten

will be shorten to:

http://example.com/a-very-long-slug-with/slug-with-exactly-five-words/another-pretty-long-sentence-that

Following example limits the number of words to 5 but you can easily change the number in $max_words variable.

How to shorten WordPress native slugs?

It is also possible to truncate the long WordPress slugs and make them shorter. To truncate the slugs to 5 words (you can alter this value inside the code) please use the following snippet. Please note that the filter will be applied to the new slugs only and if you would like to use it also for the old ones, you will need to regenerate the native slugs.

Was this article helpful to you? Yes No