1

I am moving a custom website with a WP blog to WP in one install

The old URL was: domain.co.uk/blog/post-name

The New URL is currently (while using a Category URL rewrite of /%category%/%postname%/ ) domain.co.uk/blog/category/post-name

Is there a way to remove the child category from the URL so it will be the same as the the old URL (so I don't need to 301 redirect all the old url's)

The client still wants the posts to be categorised hence the need for the custom permalink

1 Answer 1

4

You can use the post_link_category filter to remove child categories from permalinks:

function wpse147453_remove_child_categories_from_permalinks( $category ) {
    while ( $category->parent ) {
        $category = get_term( $category->parent, 'category' );
    }

    return $category;
}
add_filter( 'post_link_category', 'wpse147453_remove_child_categories_from_permalinks' );
0

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.