WordPress.org

Ready to get started?Download WordPress

Forums

Remove Permalink Slug from Custom Post Type (10 posts)

  1. fatalx
    Member
    Posted 3 years ago #

    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

    mysite.com/cars/thepostname/

    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?

    Thanks

  2. fatalx
    Member
    Posted 3 years ago #

    anyone?

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

  4. fatalx
    Member
    Posted 3 years ago #

    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.

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

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

    '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!

  6. fatalx
    Member
    Posted 3 years ago #

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

  7. 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?

  8. Mike Stop Continues
    Member
    Posted 3 years ago #

    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
    /top-level/second-level/third-level/etc

    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...

  9. Joakim Ling
    Member
    Posted 2 years ago #

    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: http://www.ultimatewebtips.com/remove-slug-from-custom-post-type/

    Hope that's what you looking for

  10. shahar
    Member
    Posted 2 years ago #

    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)

Topic Closed

This topic has been closed to new replies.

About this Topic