Remove base slug from hierarchical custom post type


for SEO reasons I try to remove the base slug of my custom hierachical service post type (example name: “custom-service”). These method is called SEO siloing. I tried different methods to achive the following url result.

How it shouldn’t look:

How it should look:

I used following tutorials to realize these structure:

There are some people with the same problem:

At first I had implemented the solution of the first tutorial from Matthew Boynes. Everything is working except for my pagination. If I use these solution, my pagination stops working.
Maybe the following code from the function add_rewrites() breaks the pagination:

add_permastruct( 'custom-service', "%custom-service%", array(
    'ep_mask' => EP_PERMALINK

You can’t call the pages of my blog. The following urls stop working:

In my second try I removed Matthew Boynes code. A blog without a pagination within its archive is useless. Then I’ve implemented the solution from “”. To make the code working for hierachical post types you have to modify the tutorials filter function for post_type_link:

function remove_custom_service_slug( $post_link, $post ) {
    if ( 'custom-service' === $post->post_type && 'publish' === $post->post_status ) {
        if( $post->post_parent ) {
            $parent = get_post($post->post_parent);
            $post_link = str_replace( '/' . $post->post_type . '/' . $parent->post_name . '/', '/', $post_link );
        } else {
            $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
    return $post_link;
add_filter( 'post_type_link', 'remove_custom_service_slug', 10, 2 );

But there is one big problem. It removes the base slug and the parent service slug:

Its a bit frustrating. Maybe someone have experience with removing the base slug of an hierarchical post type and a good hint for my project.

If you have any questions, or if you would like further information or code, please don’t hesitate to contact me.

Thanks for reading my question!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s