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
- How do I add a tag slug to a category URL to filter posts?
- WordPress link to post links to category (loop)
- How can I display the number of post associated to a category in Twig/Timber WordPress? [closed]
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Page get parameter doesn’t work with is_single() function
- Is it possible to have a template that works on multiple categories where the link address contains the specific category?
- How can I create custom URL routes?
- Custom template for sub-sub-categories
- What Must to Display the “mysite.com/category” URL?
- rewriterule not working
- How to use wp_list_categories with plugin category?
- Using if statement in index.php instead of creating separate template files
- How to display post in custom file not in archive file?
- Why is my sub-category template showing the wrong posts
- How to link a PDF file to a category URL
- Template for product-category page [closed]
- Add Date & Author Meta to Category Archive Page
- Use blog as base for tags and categories
- Display subcategories selectbox on each category page
- Displaying year once in category.php [duplicate]
- I would like to feature a tip on the homepage
- Redirect depending on category chosen
- 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?
- add_rewrite_rule and template redirect not working
- Category URL Management
- Different header for each category
- Category Template – Show Last Entry as Featured
- Custom post type archive category page results in 404
- Need help with major category and permalink re-organization
- Include home page template in specific category template
- Output Title of Post’s Current Category
- Showing different posts on category pages
- Displaying categories in different template problem
- Include specific category in URL automatically
- Include last post date in get_categories loop
- remove url from categories
- Remove subcategory slug from url
- Using custom structure prefix showing 404 for sub-categories
- corrupted URLs – can’t leave starting page
- Add custom categories and subcategories and posts as custom pages
- How to list posts from a sub-category that is listed in a parent category (more details below)?
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- A different permalink structure for different categories
- OK to redirect the root WordPress category slug?
- remove SLASH on single_post but KEEP on categories and parent pages
- How to set the same base url for two different taxonomies?
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Redirect empty search to another page
- 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
- Broken page redirect
- Default URL for category dropdown select option
- Post url rewriting for posts with certain category
- Category and tag urls return 404 error
- Adding a category view to a page
- Using a template page parent breaks page
- Any way to make Apache’s internal redirect work?
- Hide category name using mod_rewrite
- the_content() not showing full posts in category template
- Use different file includes for single.php
- Hide category name in URL
- Display Taxonomies in loop with template args
- Choosing different templates for categories
- Show posts from all categories
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Getting page/category content to show up in my custom page template
- Paginations in Category Page Leads to Sample Pages
- Create monthly archive for parent category
- 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?)
- Modify / Rewrite single template url structure
- One category not displaying template updates
- Page redirecting to category (IE only)
- WordPress a template for subcategories fo a given category, but not for root category
- How do I get a single page navigation depending on the previous page?
- What approach should I take for this URL structure?
- Add 1 category more to If_in_category statement
- Page permalink rewrite
- Custom Fields to Category edit page, then displaying them in a template correctly
- Template files not working for archives and categories
- Category Template – to be editable from the backend?