I'm struggling with this, despite being okay at WordPress dev.
I've created a custom post type called links
I've also created a custom taxonomy called link-type
All works fine when using archive.php
in the root of the theme.
However I want links to be a child page of resources so:
example.com/links/
would become example.com/resources/links/
And clicking on a taxonomy term link for example downloads
would take you to example.com/resources/links/downloads/
I'm aware of has_archive
and rewrite
and with_front
and slug
but can't understand how to use these to achieve the aforementioned structure.
As always, expert help is much appreciated.
When you register your post type, just add whatever you want to the slug in the rewrite argument, forward slashes are acceptable in slugs.
$args = array(
'labels' => $labels,
...
'rewrite' => array(
'slug' => 'resources/links',
'with_front' => true
),
);
This will give you https://example.com/resources/links/
, even if you have a page already at https://example.com/resources/
.
I almost forgot, you'll need to make sure your flush your rewrite rules (this can be done programatically when the CPT is registered, or you can just go to your Settings > Permalinks option page and click Save Changes to accomplish the same thing one time.