3

I have several WordPress sites working under different domains, but hosted on the same server.

I noticed that most of them will remember the old slug if changed. So it redirects to the new one if accessed. However, some of them wont do that despite being the same WordPress version.

Why is that? How can I fix it?

Note: I just noticed the only difference between the sites that remember and those that wont is that, for the former I have posts whereas for the latter I have fixed pages.

1
  • I just noticed the only difference between the sites that remember and those that wont is that for the former I have posts whereas for the latter I have fixed pages.
    – Cain Nuke
    Feb 12, 2023 at 20:13

1 Answer 1

3

WordPress keeps track of post slug change with wp_check_for_changed_slugs() function. The old slugs are saved in wp_postmeta table with _wp_old_slug meta_key and later redirects to current URL with wp_old_slug_redirect() function.

That's why even after changing a post's slug, you get redirected to the correct post.

However, WordPress doesn't do this by default with pages (or any hierarchical posts).

It's still possible to change this behaviour by hooking into post_updated action and replicate wp_check_for_changed_slugs() function for pages (or any hierarchical posts) and then implementing the redirect logic using old_slug_redirect_url hook.

However, this is not recommended.

The main reason is: pages may have multiple levels (hierarchical). For example, a child page can be page_a/child-1 and another child page page_a/child-2 (there can be many more, with multiple levels).

Now, changing page_a slug affects both child-1 and child-2 pages. So to implement this properly, while visiting both child-1 and child-2, WordPress will have to check for first child-1 or child-2 slug change, and then page_a parent slug change. This sort of multi level checks will slow down WordPress for hierarchical posts or pages.

You'll find a similar discussion in WordPress.org support.

If you still need this, it's better to use a redirect plugin and manually add the redirect for pages with old permalinks.

1
  • If you need redirection for hierarchial posts when their slug change, then Slim SEO is a good plugin that offers this functionality.
    – Anh Tran
    Feb 21, 2023 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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