Suppose articles is slug of the category.
1. Add a custom rewrite rule:
add_action('init', function()
{
add_rewrite_rule('^articles/([^/]+)/?$', 'index.php?name=$matches[1]', 'top');
}, 10, 0);
2. Filter the post link:
add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false)
{
if ( has_category('articles', $post) ) {
$post_link = str_replace("https://wordpress.stackexchange.com/" . $post->post_name, '/articles/' . $post->post_name, $post_link);
}
return $post_link;
}, 10, 4);
That’s all. Try it out in your functions.php and remember to flush your permalink structure.
References:
Related Posts:
- Custom permalink structure leads to be 404 on pagination
- How to get permalinks with category base working with sub-categories
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Filtering categories in the permalink structure
- Allow duplicate permalink slugs for posts in different categories
- How to remove category from wordpress url?
- Multiple post categories – single permalink
- How to create a custom url for a category [closed]
- How to change the category in URL for posts in multiple categories?
- How to exclude uncategorized from permalink structure /%category%/%postname%/
- How to get the url to tag & category base set by the user?
- 404 error on subcategory pages
- Categories’ hierarchy in URL
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Category links suddenly started giving 404 errors
- Best and Cleanest way to remove /category/ from category permalinks? [duplicate]
- How to display only the parent category in the permalink
- Root level category, tag, author and archive pages to work
- Categories and Tags returning 404 on the sidebar when using ugly permalinks
- Archive pagination causing 404 with permalinks structure
- Plural Category Base Slug On Category Archive Page
- custom permalinks for category archive ( custom base and no parent slug )
- WooCommerce change category url and product base
- Removing category base form links messes up the parent-child behavior
- Duplicate Category and Page URL loads Category instead of the Page
- How to set up Author archives with sub category URL
- Allow dot in wordpress permalinks (only for categories)
- wordpress wp_list_categories
- How to get category URL with the slug?
- How to Filter categories in the permalink structure
- Specifying multiple categories in URL (permalink)?
- WordPress subcategories return 404 in custom template
- force category base – archive pages work WITH & WITHOUT category base slug in url?
- How get permalink for the current category or tag?
- Add “page-a” slug to category link if user visit category link from “page-a”
- Redirect category to url with /category
- Changing permalink from /postname/ to category/postname/
- One Specific Category To Permalink
- Category being displayed without base parmalink
- wordpress sub-category ( lowercase letters + non-latin characters ) = 404
- Removing post category base giving Error 404
- How to disable default category linkbuilding?
- Show parent category in URL of subcategory archive page
- Mod_Rewrite to show only last subcategory in URL
- Permalinks: display just one kind of wp category in the posts url
- Multiple URL’s based on category for one post
- Same base for category and post
- category permalinks
- Sub Categories Keep Redirecting to Pages With Same Slugs
- How to rewrite the post URL according to the category?
- Older entries link within category page
- How can you change the permalink for pages?
- Get category URL knowing it’s id
- Remove the parent name from permalink
- How to add a post without assigning to a category?
- How to get Next/previous_post_link to go through articles in top parent category
- How to Link to Most Recent Custom Post of Same Term
- Cannon see subcategory in permalink
- Redirect Changed Permalink on wordpress
- Category url generate 404 error
- How to remove one specific category (uncategorized) from post permalinks
- How do I retrieve the category ID (ugly permalinks) in my sub-navigation menu?
- How do I change the category permalink structure?
- url for posts for a date within a category
- Advanced permalinks structure
- Categories show 404 error on multisite installation
- Subcategory Page URL to Display Only Posts from that Subcategory?
- A different permalink structure for different categories
- How to set the same base url for two different taxonomies?
- Get multiple category names from permalink
- Is it possible to set up blog categories without changing permalink structure
- Remove WP Core canonical for category pagination
- Include a page’s “category” in its URL
- Subcategory Page 404ing
- Remove base category gives 404 error
- Custom permalink /%category%/%postname%/ produces 404 on each post
- WordPress Category url redirects to subdomain
- WordPress and “pretty permalink”
- Group Posts by First Letter of Title categories
- Using categories and pages in menus
- Page Type with Category Link
- hierarchical taxonomy in permalinks? using same slug
- Allow duplicate permalink slugs for posts in different categories
- Changing Permalinks for Category Pages Only
- Link categories to last post
- Using pagination with multiple loops causes it to break
- How to include first assigned category in the post URL?
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- Create custom Perma link
- Custom permalinks structure
- How to get category slug link? ( include parent categories)
- Category archive page has two URLs even when default theme is active with no active plugins
- Remove “?category=” in the URL wordpress ajax filter work for category
- Use same wordpress category base and tags as the prefix as the post permalink
- How to add custom prefix before category base for category page URL?
- WordPress how to remove parent slug from category URLs
- How to remove the category from the url only for a specific category of articles on wordpress
- Display last category child in permalink
- Link from page to category posts
- How do we ReWrite HTACCESS to point a cat/subcat Product URL, to Cat/ only?