Search code examples
phpwordpressurlstructurecustom-post-type

Remove URL structure for custom post type


I would like to know if its possible to remove URL structure for a custom post type. For example, I have 2 custom post types: portfolio and slider.

I want to keep URL structure for portfolio post type like this: mysite.com/portfolio/item-1 etc.

But I dont want URL structure for slider posts, since the slider will only be shown on the home page and I dont want visitors to be able to access it by going to mysite.com/slider/slide-1 for example. Is it possible?

Thanks in advance :)

Wordpress forums post: http://wordpress.org/support/topic/no-url-structure-for-custom-post-type-1?replies=1


Solution

  • When you do register new custom post you're using register post type, right? There are options

    'rewrite'            => false,
    'query_var'          => false,
    'publicly_queryable' => false,
    'public'             => false
    

    After WordPress documentation:

    rewrite Triggers the handling of rewrites for this post type. To prevent rewrites, set to false.

    query_var 'false' - Disables query_var key use. A post type cannot be loaded at /?{query_var}={single_post_slug}

    publicly_queryable Whether queries can be performed on the front end as part of parse_request().

    public 'false' - Post type is not intended to be used publicly and should generally be unavailable in wp-admin and on the front end unless explicitly planned for elsewhere.

    Now go to Permalinks Settings and without changing anything - save change. It will rebuild your "routing".

    Such setup will disable your custom post from frontend.