1

My customer has a WP 4.6.1 with many posts (10000+) on GNU/Linux. Active permalink option is "post name". He asked me to shorten the permalinks for SEO reasons so that each URL contains only the first five words of the post name. He obviously wants the current permalinks (all the words) to keep redirecting to the new scheme.

I have two problems, which I think are very related one to the other:

  1. I need to describe the new permastruct some way. Unfortunately I don't find add_permastruct documentation very clear and I don't even understand if it is at all possible. As an alternative, I could shorten the slugs in the database with some SQL query or script, but that wouldn't take new posts into account.
  2. I need to redirect the old URLs to the new ones: here I think I need to describe (again!) the new permastruct this time using a regexp to add_rewrite_rule, because I need to say something like when the permalink is longer than five words, redirect to the one made of five words only, so I need to count the number of dashes in the permalink and then extract the substring to build the redirect destination.

For the time being let's focus on the first problem only, because the second one is a good SO question on its own.

What arguments should I use to describe the new permalink structure to add_permastruct?

Your Answer

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

Browse other questions tagged or ask your own question.