permalinks - Rewrite Rule for default post type

admin2025-06-05  3

I am using two post types into my site: a) Post ( default post type ) b) Program ( Custom Post Type ) I am trying to add '/blog/' string to default post type URL. If I am tying to do it from permalink option in admin panel then it will aslo add the string to Program post type but I want it as following:

a) example/blog/post-name/ b) example/program/program-name/

Thanks in advance.

I am using two post types into my site: a) Post ( default post type ) b) Program ( Custom Post Type ) I am trying to add '/blog/' string to default post type URL. If I am tying to do it from permalink option in admin panel then it will aslo add the string to Program post type but I want it as following:

a) example/blog/post-name/ b) example/program/program-name/

Thanks in advance.

Share Improve this question asked Dec 10, 2018 at 13:11 Pardeep SinghPardeep Singh 232 bronze badges 1
  • 1 This is controlled by your post type registration code, please edit your question and add your code. – Milo Commented Dec 10, 2018 at 14:04
Add a comment  | 

1 Answer 1

Reset to default 1

When you register your custom post type using register_post_type function, you have to be very careful with rewrite param.

You should pass an array with following keys:

  • slug => string Customize the permalink structure slug. Defaults to the $post_type value. Should be translatable.
  • with_front => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true
  • feeds => bool Should a feed permalink structure be built for this post type. Defaults to has_archive value.
  • pages => bool Should the permalink structure provide for pagination. Defaults to true
  • ep_mask => const As of 3.4 Assign an endpoint mask for this post type. For more info see Rewrite API/add_rewrite_endpoint, and Make WordPress Plugins summary of endpoints. If not specified, then it inherits from permalink_epmask(if permalink_epmask is set), otherwise defaults to EP_PERMALINK.

In your case, setting with_front to false for your CPT should solve your problem.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749111023a316452.html

最新回复(0)