Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement