This solution enables you to create your own custom permalink structure for any custom post type ( CPT ).
Note: The entire code for creating CPT’s, Taxonomies and everything else you need is included in this post so all you need to do is copy, paste and swap out the names with your own.
This example assumes you have created 2 custom taxonomy types:
- the 1st named country
- the 2nd named region
Here’s a working example of what the permalink structure looks like for a single CPT:
http://example.com/golf-resort/scotland/st-andrews/british-open-golf-championship/
example.com – your domain
gold-resort = name of custom post type
scotland = country ( taxonomy )
st-andrews = region ( custom taxonomy )
british-open-gold-championships = entry site for single CPT
Here’s what the Edit Page looks like for each single CPT:
Once you add the code, you can create your own custom taxonomies and use them with one or more custom post types.
Here’s the code:
The code creates 2 CPT’s named golf course and golf resorts which include taxonomies for country and region.
I tried this and I got two post types golf reorts and golf courses and I have no idea how to change/edit these as they don’t show up in the CPT. (FYI: I uploaded the above code using snippets plugin for WP).
If you don’t mind me elaborating, I am looking for something like this (and honestly I am not technical enough to edit the above code snippet):
One custom post type called hub which will have 4-5 categories in it like blogging, podcasts, wordpress, email marketing.
So the final URL structure should be something like this:
site.com/hub/blogging/post-url
site.com/hub/podcasts/post-url
site.com/hub/wordpress/post-url
site.com/hub/email-marketing/post-url
site.com/hub/seo/post-url
Also, can I add sub categories to the above topics without including them in the URL, like hosting can have a sub category called site.com/hub/wordpress/themes but the posts under it should have the URL structure as site.com/hub/wordpress/post-url
Thank you 🙂
-Swadhin
You’ll need to swap out the name of the CPT and custom taxonomy type in the code. This code works with custom taxonomy types for CPT’s NOT categories which are used for standard posts.
Try this https://wpsites.net/web-design/add-taxonomy-term-slug-to-cpt-permalink/
Hi there,
I am using GeneratePress theme and want to use CPT that allows you to add taxonomy in the URL structure.
The above code is great but it also has 2 more related codes (links to related posts) for similar action.
May I know which is the recommended one to follow?
P.S. In case you need, I want to create a custom structure like https://example.com/hub/seo/what-is-seo for my site. 🙂
Try them out and see which one works for your case.