Removing Parent Page(s) from Permalink

a quick search shows another stackexchange topic on this, and it used this code to cleanup the permalink of parents/ancestors:

function wpse_101072_flatten_hierarchies( $post_link, $post ) {
    if ( 'page' != $post->post_type )
        return $post_link;

    $uri = '';
    foreach ( $post->ancestors as $parent ) {
        $uri = get_post( $parent )->post_name . "https://wordpress.stackexchange.com/" . $uri;
    }

    return str_replace( $uri, '', $post_link );
}
add_filter( 'post_type_link', 'wpse_101072_flatten_hierarchies', 10, 2 );

You can find that discussion here: Removing parent slug from URL on custom post type

Leave a Comment