add_filter('term_link', 'remove_parent_category_slug', 10, 3);
function remove_parent_category_slug($termlink, $term, $taxonomy) {
// Only apply to categories
if ($taxonomy === 'category') {
// Check if the term has a parent
if ($term->parent != 0) {
// Get the slug of the current term
$termlink = home_url('/' . $term->slug . '/');
}
}
return $termlink;
}