Search code examples
phpwordpresscustom-post-typeslug

URL showing unnecessary post types in WordPress


My website, let's call it example.com, has a few Post Types:

 - Post (the default post type) with the slug 'blog'
 - Cases with the slug 'cases'
 - Klanten with the slug 'klanten' (Dutch word for clients)

When I go to the blog page, the url shows like this:

example.com/blog/

And when I then navigate to a blog post, it shows this:

example.com/blog/blog-title/

This is also good.


But now the problem. When I go the the cases page, the URL shows like this:

example.com/cases/

This is fine, but when I select a case, the URL shows like this:

example.com/blog/cases/case-title/

Ofcourse, I want this URL to be:

example.com/cases/case-title/

Solution

  • Try to call register_post_type() param 'rewrite' with additional argument 'with_front' => false

    From Codex documentation: '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

    $args = array(
        /*other args*/
        'rewrite' => array('slug' => 'cases', 'with_front' => false),
        /*other args*/
    );
    register_post_type( 'cases', $args );