I have a custom post type with the rewritten slug of plugin
creating the url structure of http://site.com/plugin/plugin-slug/. Which makes the CPT Archive as http://site.com/plugin/
I’d like to rewrite it, without using a page and a custom page template, to use http://site.com/plugins/ (Which is the labels=>Name
in the CPT). while keeping the slug for the single posts as /plugin/
This would also need to support things like `/plugins/page/21 – which it currently does.
1
When you register the post type, set the argument 'has_archive'
to a string, in your case plugins
.
The doc block for register_post_type()
says:
@type bool|string $has_archive
Whether there should be post type archives, or if a string, the
archive slug to use. Will generate the proper rewrite rules if
$rewrite
is enabled. Defaultfalse
.
Minified example:
register_post_type( 'plugin', [ 'has_archive' => 'plugins' ] );