I have this custom structure set for my permalinks: /archive/%postname%
With this, my URLs show as example/parent/child, which is the desired behavior. However, I'm adding a custom post type and this permalink structure is causing undesired URLs for the CPT. I want the permalink to be example/news/headline, but I'm getting example/archive/news/headline.
Here's my CPT:
register_post_type('news', array(
...
'public' => true,
'rewrite' => array('slug' => 'news'),
'supports' => array( 'title', 'page-attributes', 'editor', 'custom-fields')
));
Is there a better permalink structure I could use to achieve the URLs I require? Or is there something missing/wrong in my CPT that would fix this issue?
I have this custom structure set for my permalinks: /archive/%postname%
With this, my URLs show as example/parent/child, which is the desired behavior. However, I'm adding a custom post type and this permalink structure is causing undesired URLs for the CPT. I want the permalink to be example/news/headline, but I'm getting example/archive/news/headline.
Here's my CPT:
register_post_type('news', array(
...
'public' => true,
'rewrite' => array('slug' => 'news'),
'supports' => array( 'title', 'page-attributes', 'editor', 'custom-fields')
));
Is there a better permalink structure I could use to achieve the URLs I require? Or is there something missing/wrong in my CPT that would fix this issue?
Share Improve this question asked Apr 23, 2020 at 16:51 Sue ASue A 133 bronze badges2 Answers
Reset to default 1Disable the with_front
on rewrite
while register_post_type
.
In your case:
register_post_type('news', array(
...
'public' => true,
'rewrite' => array('slug' => 'news', 'with_front'=> false),
'supports' => array( 'title', 'page-attributes', 'editor', 'custom-fields')
));
You can just use the "Post name" permalink structure, which is the same as /%postname%/
. Pages will use the /parent/child/
structure, and your CPT - as-is - will use /news/%postname%/
.