Maarten Wolfsen Maarten Wolfsen - 1 year ago 87
PHP Question

URL showing unnecessary post types in WordPress

My website, let's call it, 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:

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

This is also good.

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

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

Ofcourse, I want this URL to be:

Answer Source

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 );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download