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.

Read More

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

Related posts

Leave a Reply

2 comments

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

  2. I had similar problem, in my case I had custom post type like this:

    mypage.com/type
    

    and inside I’ve got a lot of posts, so of course this generated for me pages looks like:

    mypage.com/type/page1
    mypage.com/type/page2
    ...
    

    BUT, I knew that in the future I’ll make websites there, so simple I made a redirection inside this custom post type webpages. So inside single-type.php I added:

    <script>
        window.location.href='www.mypage.com/404';
    </script>
    

    So this simply redirect people to 404 page. Few weeks later, when I wanted to turn on these pages, I just deleted this code.

    This is just a temporary workaround, but I hope it could help someone.