0

When i edit a single post slug the old url redirects to the new one automatically.

I need to do this in bulk.

There is a text that appears on thousands of permalinks and i want to remove it from them all and keep wp native redirect, because this text appears in random places i cannot make an htaccess rule for all posts.

So for example:

http://example.com/cpt1/hello-world-unwanted-word/
http://example.com/cpt2/unwanted-word-hello-world/
http://example.com/cpt3/hello-unwanted-word-world/

Should become:

http://example.com/cpt1/hello-world/
http://example.com/cpt2/hello-world/
http://example.com/cpt3/hello-world/

If someone access the old url redirect to the new one.

  • You should check first to make sure the new URLs will not create any duplicate slugs. Having /cpt1/hello-world/ and /cpt2/hello-world/ should work because they are different post types and so they have different overall URLs, but if you wind up with two /cpt1/hello-world/ posts then only one will be accessible. – WebElaine Nov 20 '19 at 14:22
  • I see. They are very different except for these unwanted words. I found a workaround i will post later on!!! – Michael Rogers Nov 20 '19 at 14:43
0

This is what worked for me:

 function remove_false_words($slug) {
     if(!is_page())
  if (!is_admin()) return $slug;
  $keys_false = array('unwanted','word');
  $slug = explode ('-', $slug);
  $slug = array_diff($slug,$keys_false);
  return implode ('-', $slug);
}
add_filter ('sanitize_title', 'remove_false_words');

Then you can use wordpress dashboard to select all posts, bulk edit, Update. And the words will be removed from slugs with native redirect.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.