Try something like this:
function custom_rewrite( $wp_rewrite ) {
$feed_rules = array(
'(.+)/blog/(.+)' => 'index.php?custom_tax='.$wp_rewrite->preg_index(1).'&post_name=" . $wp_rewrite->preg_index(2)
);
// ( array merge must be done this way, to ensure new rule comes first )
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
// refresh/flush permalinks in the dashboard if this is changed in any way
add_filter( "generate_rewrite_rules', 'custom_rewrite' );
Remember to flush permalinks by visiting the permalinks page and re-saving if you add/change this code. Also remove the flush_rewrite_rules();
as advised by Stephen, it’s unnecessary and bad practice.
Related Posts:
- Can’t get a custom template taxonomy page to display
- Custom taxonomy listing page when no term set (all terms)
- Removing taxonomy base using WP rewrite
- Custom taxonomy on permalink
- How to enable hierarchical permalinks for hierarchical taxonomies
- Remove Custom Taxonomy Base
- How can I set up a category “overview” page?
- Nice URLs for a Custom Post Type List with a Shared Custom Taxonomy?
- Dynamic page slug for Custom Taxonomies?
- How to fix a double slash in custom permalinks with hierarchical taxonomy’s?
- Getting archive pages in WP’s AJAX internal link finder?
- custom taxonomies on permalink
- Pros and cons of using [taxonomy name] in place of [category name]?
- Permalinks for quote authors
- Change in custom taxonomy permalink causes 404 error for another custom taxonomy
- custom taxonomy archive permalink shows 404 error
- Custom taxonomy term in WooCommerce product permalink
- Change URL structure of subcategory archive pages
- Add parent/child taxonomy to custom post type url
- Keep taxonomy base name in post permalinks
- Change permalink of post if it belongs to custom taxonomy
- Permalinks for custom taxonomy stopped to work
- Date archive permalinks for custom taxonomy
- Custom permalinks with hierarchical taxonomy – getting PHP warning
- How do I modify taxonomy term slugs dynamically?
- Permalink help with default Posts and custom Taxonomy
- how to change permalinks format for pagination?
- Replace taxonomy permalinks
- How do I create a permalink structure with 2 taxonomies
- Base permalink for custom taxonomy
- Rewrite Rules returning wrong data
- How to change url for taxonomy pages?
- Query custom taxonomy by term id?
- How to customize custom taxonomy url?
- Duplicate slug/permalink issue
- How to add hierarchical taxonomy with parent child relation to URL?
- WordPress modify Settings > Permalinks (options-permalink.php) Add CPT Permalink Options
- How can I add a custom permalink to a term?
- Permalinks with custom taxonomies and regular categories
- Need equivalent of single_term_slug
- 404 Error on Custom Post Type / Custom Taxonomy
- How to define %category% for custom taxonomies?
- Custom Permalink Structure for terms/taxonomies of custom post type
- How Can I Remove Child Slug From Grandchild Slug When Using Duplicate Grandchild Slugs?
- Change the full permalink (URL) of a single post by connecting it to a specific page
- Prioritise Pages over Taxonomy Term Root Archive, but not Taxonomy Term Child Archives
- How can I rewrite the URL of my custom taxonomy to include the year?
- How do I get the correct URL?
- Remove custom taxonomy slug from URL
- How to replace custom post type with custom taxonmy in permalinks
- Get taxonomy link with post type slug prefix
- How To Create Dynamic Permalink To Custom Taxonomy List of Current Posts?
- Restructuring permalink with more than one taxonomies
- Custom taxonomy return 404
- Permalinks incorrectly inserting multiple categories
- WordPress Taxonomy Permalinks – Custom?
- Need help understanding a rewrite with multi-level taxonomy
- Broken paths on taxonomies after changing permalink to post name
- Custom taxonomy rewrite in permalinks for posts gives 404 on pages
- Permalink Rewrite to include Custom Taxonomy Term
- Multiple taxonomies, what should the permalink look like?
- Taxonomy to WordPress Permalinks of custom post type
- Permalinks not working on MU network with domain mapping
- Optional taxonomy in cpt permalink
- post_type_link not working for posts without terms
- Child terms with improper parent in the url should redirect to 404
- Using Custom Taxonomy in Default Post Slug
- How to handle custom taxonomy archive when no posts will have that taxonomy
- Adding Category to Child Posts Permalink
- Custom post types, taxonomies, and permalinks
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Using wp_query is it possible to orderby taxonomy?
- Permalinks: custom post type -> custom taxonomy -> post
- Mixing custom post type and taxonomy rewrite structures?
- “tax_query” parameter not working with WP_Query
- How do I exclude a custom taxonomy from the post loop
- get_posts assigned to a specific custom taxonomy term, and not the term’s children
- How can I get only parent terms?
- Remove taxonomy slug from a custom hierarchical taxonomy permalink
- How to modify a taxonomy that’s already registered
- Retrieve posts by term id custom query
- Change order of Custom Taxonomy List
- Get the the top-level parent of a custom taxonomy term
- get_the_term_list without links in 3.1
- Inserting terms in an Hierarchical Taxonomy
- get_terms – only top level
- Rewriting a custom-post-type permalink with taxonomy term?
- Custom taxonomy terms not showing as list Gutenberg Editor
- Altering the appearance of custom taxonomy inputs
- How to only list the child terms of a taxonomy and not their parents?
- Get term SLUG by term ID
- Is ACF being a honey trap? [closed]
- Shouldn’t this be easy?! Custom post type/custom taxonomy permalink
- Get term name from term ID?
- Check if Current Category has Children
- How to use taxonomies on attachments with the new Media Library?
- Hierarchical taxonomy UI
- WordPress taxonomy radio buttons
- How to prevent new terms being added to a custom taxonomy?
- Custom taxonomy, get_the_terms, listing in order of parent > child