[wp-trac] [WordPress Trac] #34136: Allow register_post_type's rewrite to remove CPT slug

WordPress Trac noreply at wordpress.org
Fri Oct 2 23:21:00 UTC 2015


#34136: Allow register_post_type's rewrite to remove CPT slug
---------------------------+-----------------------------
 Reporter:  BenRacicot     |      Owner:
     Type:  enhancement    |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Rewrite Rules  |    Version:  4.3.1
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Not sure if there are reasons (outside of naming conflicts) why
 register_post_type's rewrite does not allow an empty value as an argument
 to remove the post type slug from its future post URL's.

 After a lot of research and some code from @JanBeck at my
 wordpress.stackexchange question:
 [http://wordpress.stackexchange.com/questions/203951/remove-slug-from-
 custom-post-type-post-urls] its clear that naming conflicts between a CPT
 and Page type URL's are being avoided.

 I propose:

 {{{
 'rewrite' => array( 'slug' => '', 'with_front' => false ),
 'has_archive' => 'something',  // will now default to false to avoid
 possible conflict
 }}}

 then proper rewrite rules should be added to allow for the removal of this
 CPT slug and disallow the CPT to create conflicting URLs in the future. eg
 publishing ones that match page URL's the same as native posts append a
 '-1' to a conflicting URL.

 This will solve a large problem where users are trying to hack around this
 by creating their own rewrite rules, hacking post.php, and pre_get_posts
 solutions.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34136>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list