Rewrite Custom Post Type to Remove Slug | Pressimply | 170219

So, you’ve created a shiny new Custom Post Type with some code and you need to rewrite your CPT to remove the slug, eh… ?

Perhaps it generates URLs something like this :

https://mydomain.com/custom-post-type-slug/custom-post-title/

– but what you really need is :

https://mydomain.com/custom-post-title/

Luckily, it’s super-simple to correct.

When registering your CPT (Custom Post Type), add the following to the arguments array :

'rewrite' => array( 'slug' => '/', 'with_front' => false )

Simple as that. You’re done.

Looking for the full lowdown on creating Custom Post Types in WordPress… ?

You’ll want to check out the documentation here :

https://codex.wordpress.org/Function_Reference/register_post_type

There’s also a super-handy automated snippet generator tool over at GenerateWP.

Published by Pressimply