I’m creating a new website based on a theme using custom post type and WordPress 3.2.1.
The problem is that my content was previously using %postname% permalinks and all my SEO is build on this. Using CPT add a slug like : http://mysite.com/slug-cpt/postname
I tried this rule in the register_post_type function but it doesn’t work :
‘rewrite’ => array(‘slug’ => false, ‘with_front’ => false)
I also read this but it’s not good for me : Permalinks in Custom Post types
Any idea ?
This is a tricky one, I had exactly the same problem but after a lot of debugging and troubleshooting I managed to fix it.
The trick is to add a new rewrite rule:
Question is quite old, but issues still exist.
The best way to remove the slug from URL is writing a few lines of code in your
functions.php
file.Another way to do it is passing the rewrite parameters as follows:
But this is not recommended as it causes 404 error in other pages. So you should opt for the solution of getting into your theme’s
functions.php
.This will remove the slug from the URL for the published post. This will still cause an error since it specifies that only ‘post’ and ‘page’ post types can have url without a post-type slug.
Now to teach WP that out CPT will also have URL without slug, we need to get this in our
functions.php
Ref: https://wordpress.stackexchange.com/a/320711/98322