If you want to remove the ‘/category’ base from your category permastructs, you’re in luck. There’s a simple way to do it with a bit of code. It happens in two parts:
/**
* Remove the '/category/' from the base, but include the parent category if it's a child
*/
add_filter( 'category_link', 'vipx_filter_category_link', 10, 2 );
function vipx_filter_category_link( $link, $term_id ) {
return '/' . get_category_parents( $term_id, false, '/', true );
}
/**
* Add the necessary rewrite rules for our categories to be properly handled
*/
add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules' );
function vipx_filter_category_rewrite_rules( $rules ) {
$categories = get_categories( array( 'hide_empty' => false ) );
if ( is_array( $categories ) && ! empty( $categories ) ) {
$slugs = array();
foreach ( $categories as $category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
if ( 0 == $category->category_parent )
$slugs[] = $category->slug;
else
$slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
}
}
if ( ! empty( $slugs ) ) {
$rules = array();
foreach ( $slugs as $slug ) {
$rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')(/page/(\d)+/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}
Keep in mind that you’ll need to flush your rewrite rules the first time this code is added to your theme. You’ll also need to flush rewrite rules each time your categories change.
WordPress.com VIP clients can initiate the flush rewrite rules process with wpcom_initiate_flush_rewrite_rules(). Please use it sparingly.