I recently had a need to rewrite the URLs of all parent and child pages in a custom post type so that they appeared to live at the website root, but in reality, continued to live in a custom post type within their hierarchy.
Preface
The situation:
- I have a page called
Services
that lives atdomain.com/services
. - I have a custom post type called
Services
. - I have
Services
post calledProgramming
that lives atdomain.com/services/programming
. - I have
Services
post calledWeb Development
, that is a child ofProgramming
, that lives atdomain.com/services/programming/web-development
.
The goal:
- The
Services
page should remain where it is i.e.domain.com/services
. - The
Programming
post should appear to live at the website root i.e.domain.com/programming
. - The
Web Development
service should also live at the website root i.e.domain.com/web-development
.
The reason:
- Shorter URLs.
- Keep all website pages together.
- Keep all services together.
- Maintain hierarchy of services.