This should work:
add_action( 'init', 'wpa12742_init' );
function wpa12742_init(){
add_rewrite_rule( 'category/(.+?)/(\d{4})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]', 'top' );
add_rewrite_rule( 'category/(.+?)/(\d{4})/page/(\d+)/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&paged=$matches[3]', 'top' );
}
EDIT
On second thought, that’s not enough, since you’ll get caught by redirect_canonical()
.
Add this too:
add_filter( 'term_link', 'wpa12743_term_link', 10, 3 );
function wpa12743_term_link( $link, $term, $taxonomy ){
if('category' != $taxonomy && !preg_match( '@^\d{4}$@', get_query_var('year') ) )
return $link;
return trailingslashit( $link ) . get_query_var( 'year' );
}
Related Posts:
- Add forward slash on categories url (serve one version of a url)
- How to? Redirect /category/sci-fi/ to /category/scifi/?
- How to set up Author archives with sub category URL
- How to change category and year archive permalinks/rewrite rules?
- Category link redirect to custom template page instead of index.php?
- Custom url structure – pages under a custom post type
- Redirect Problems with Archive Page and GET variables
- How to remove parent category from child category url using wordpress rewrite rule?
- Remove “category” from permalink with add_rewrite_rule
- WordPress Category url redirects to subdomain
- wordpress category rewrite rule with pagination
- Best Way to Redirect Category to Page and Hide Category
- Filtering categories in the permalink structure
- Multiple post categories – single permalink
- Make all subcategories use the template of its category parent?
- Custom post types with their own permalink structure
- Optimal way to redirect home page to category archive?
- Rewrite category wordpress
- How do I add a add_rewrite_rule without it redirecting?
- Category and tag with same name
- Rewrite category slug
- Changing the category permalink structure
- How do I set a specific template for sub-categories?
- Exclude subcategories from the url
- How to display only the parent category in the permalink
- How to override Category rendering mechanism
- How to control template resolution if both Author and Category filter in place?
- Custom rewrite rule
- Custom Category/Subcategory structure
- How to show in search results posts with a particular tag in a particular category?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Default category link for a custom category is a broken link
- Code to pull in a PHP file named after the category ID
- Categories not working – 404 Not found error
- What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?
- Are Category or Tag Archive Pages Possible?
- Possible to make a subdirectory that loops through a single category?
- Set a them for all subset of category
- Load an url with minimal/no DB queries
- How to display only posts assigned to a particular, isolated, subcategory
- Highlight wp_nav_menu when category is selected
- How do I get rid of “category” from my URL structure?
- WordPress category page redirects in .htaccess not working
- Why do my categories redirect?
- Different templates for different category tags
- Rewrite Rules to custom template
- Category archive rewrite rule to include category/subcategory?
- The default code for “posts_nav_link” on category.php isn’t working
- Read GET parameters in APACHE Mod Rewrite rules for WordPress categories in Posts
- Only one post is showing on category page, why?
- WP didn’t redirect to canonical category URL
- Add /category/ to an author archive page
- Remove subcategory and category with some rules from permalink
- WordPress URL Rewrite for dynamic and customized URL
- Flat category URLs but retaining hierarchy?
- Does “show_option_all” in wp_list_categories do anything?
- redirecting from a general category page to another specific one
- How to insert category list into post creation page, and retrieve chosen categories?
- How do I add a tag slug to a category URL to filter posts?
- WordPress link to post links to category (loop)
- Page get parameter doesn’t work with is_single() function
- How can I create custom URL routes?
- What Must to Display the “mysite.com/category” URL?
- Using if statement in index.php instead of creating separate template files
- How to link a PDF file to a category URL
- Template for product-category page [closed]
- Displaying year once in category.php [duplicate]
- How to differentiate the homepage structure from the category page structure in WordPress template?
- How can I include custom category and tag base in template files?
- Need help with major category and permalink re-organization
- Include home page template in specific category template
- Showing different posts on category pages
- remove url from categories
- corrupted URLs – can’t leave starting page
- A different permalink structure for different categories
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Remove part from dynamic url and redirect
- Category pages redirecting to tab on Posts page grid
- Custom Archive Template for Multiple Categories
- How do I rewrite a single category link to point to a custom page?
- Category custom template is not showing correct posts
- Default URL for category dropdown select option
- Category and tag urls return 404 error
- Hide category name using mod_rewrite
- Choosing different templates for categories
- Show posts from all categories
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Paginations in Category Page Leads to Sample Pages
- hierarchical taxonomy in permalinks? using same slug
- Most efficient way to have 1 template for parent, 1 template for child categories?
- Category Templates for Post Types not Working
- htaccess redirect for all categories converted to tags now showing 404
- Migration from old CMS to WordPress 301 redirection rules?
- WordPress permalink still not working (error or not understood?)
- One category not displaying template updates
- How do I get a single page navigation depending on the previous page?
- Add 1 category more to If_in_category statement
- Category Template – to be editable from the backend?
- have_posts is empty on category.php
- How to create a template for categories