Support » Fixing WordPress » Remove Permalink Slug from Custom Post Type

  • Hello,

    I have created a custom post type named “cars” and now every post that I make with this post type has the “cars” slug before it. I don’t want that.

    so all my posts look like this

    I have used

    'rewrite' => array(
    		'slug' => '')

    when registering the post type but that didn’t work. Does anyone know how to remove the custom post type slug from my permalinks?


Viewing 9 replies - 1 through 9 (of 9 total)
  • anyone?

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    That’s how it’s supposed to work, otherwise you shouldn’t be using the CPT.

    Maybe something is wrong with my complete code

    [Code moderated as per the Forum Rules. Please use the pastebin]

    if I make slug => ‘anything’ that permalink does change I just cant get it to go away.

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    No, that’s what it’s supposed to do. Your Custom Post Type slug is in your URL.

    ‘slug’ – prepend posts with this slug – defaults to post type’s name – use array(‘slug’=>$slug) to customize permastruct

    You can’t make it NOT exist or it would cause collisions with the rest of your posts!

    so there so no way to not have a permalink slug for custom posts?

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    Correct. You cannot have a Custom Post Type without a permalink slug.

    Okay, yes, I’m sure you could hack the heck out of it, but at that point, you are NO LONGER using it as intended. Why not use post formats instead?

    One great example is that your content type is a hierarchy that has only one root — there’s no reason that your url shouldn’t be able to be

    Another superb example is that you want to replace the ‘page’ content type with something that has a few more options. There should be some simple way to allow the user to take responsibility for collisions…

    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

    function book_rewrite_rule() {
    	add_rewrite_rule('(.*?)$', 'index.php?book=$matches[1]', 'top');
    add_action('after_theme_setup', 'book_rewrite_rule');

    I posted on my blog a step by step guide:

    Hope that’s what you looking for



    I’d like to see

    'rewrite' => array('slug' => '')

    work. /top-level/second-level/third-level/etc is a common and acceptable reason why this should be possible.

    (thanks jocke_gbg)

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove Permalink Slug from Custom Post Type’ is closed to new replies.