11

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 Answer 1

21

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. Default false.

Minified example:

register_post_type( 'plugin', [ 'has_archive' => 'plugins' ] );
1
  • 6
    To refresh the rewrite rules for a custom post type you are updating, visit Settings > Permalinks. Based on the example above, if you don't do this, /plugin will still be the archive slug and /plugins won't work yet. Apr 1, 2015 at 11:13

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .