How to remove custom post type name from base url?

How can I remove custom post type slug from my base url ?
for eg : mywebsiteurl.com/custom-post-slug/postname
I would like to make it mywebsiteurl.com/postname instead .

1 Answer
1

I’m not sure why you would want to do this in the first place or need custom post types. Removing the post type name from the URL completely would most likely cause conflicts between posts and pages. One way would be to have your permalinks just /%postname% (change in Settings > Permalinks on the dashboard).

In the code of which you register your custom post type there is a rewrite property which lets you change the slug value from post-type-name/post-name (the post-type-name bit) to something else using 'rewrite' => array('slug' => 'this-is-the-new-slug-value'). If you want to remove the slug, maybe using CPT isn’t such a good idea in the first place, as the slugs give the URL’s some form of hierarchy and prevent conflicts.

As far as I know, there is no standard out-of-the-box solution to remove it completely, not having a slug wouldn’t make any sense, so I don’t forsee such functionality being added into the core. Having said that, if you must remove it, this blog post details a solution for removing it. I’m not sure how well it works but appears to work based on what I’ve seen and will do what you’re asking.

Also: Welcome to the site Kuldeep.

Leave a Comment