最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Permalinks for parentchild pages and custom post types

programmeradmin6浏览0评论

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 badges
Add a comment  | 

2 Answers 2

Reset to default 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')
));

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

发布评论

评论列表(0)

  1. 暂无评论