1

I have this custom structure set for my permalinks: /archive/%postname%

With this, my URLs show as example.com/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.com/news/headline, but I'm getting example.com/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?

2 Answers 2

1

Disable 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')
));
1
  • This is what worked for me. At first my CPT pages were showing 404 after adding "with_front => false", I then disabled & reenabled all plugins and it started working. Thank you!
    – Sue A
    Apr 23, 2020 at 18:45
0

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%/.

1
  • I get a 404 error for all child pages when trying to use "Post name" permalink structure.
    – Sue A
    Apr 23, 2020 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.