Custom post type within a subdirectory

I’ve searched around but have not been able to find an answer to my question.

What I’m trying to do is create a custom post type that exists within a sub-directory, not just after the root as is default.

For example right now I have:

http://www.mysite.com/custom-post-type

I would like to have:

http://www.mysite.com/subdirectory/custom-post-type

The reason I’m trying to do this is that I have a client that now has additional clients that I would like to have named as a sub-directory, and not an entirely new sub domain.

I was planning on creating custom post types to create the additional blogs or the two other clients, but I can’t find a way of having a sub-directory first.

Is there an easy way to do this? I’m decently versed in WP but not an expert, so I’m hoping there is an easy-ish method.

Thanks for any guidance

1 Answer
1

When you register your post type, add the subdirectory to the has_archive argument, and as the slug argument of the rewrite argument:

$args = array(
    // ... other args removed for clarity
    'rewrite' => array( 'slug' => 'subdirectory/custom-post-type' ),
    'has_archive' => 'subdirectory/custom-post-type',
    // ...
);
register_post_type( 'your_cpt', $args );

Leave a Comment