No URL structure for custom post type (3 posts)

  1. RichardMisencik
    Posted 2 years ago #

    Hello guys, 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 its only showing 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 :)

  2. antekdesign
    Posted 2 years ago #

    Hi Richard,

    As far as I know it is not possible to do not give any URL to a CPT.
    You may set the meta robots to noindex nofollow for the pages so that they won't be indexer on search engines. You can do it using the plugin: WordPress SEO by Yoast.

    Or you can create a single-slider.php file and insert a redirection to the home page so that the pages are not accessible directly.

    You could use something like:

    <?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>

    I don't know if this solution would be ok for you... just my 2 cents.


  3. RichardMisencik
    Posted 2 years ago #

    Hi antekdesign, I managed to get it working by changing public -> true to false. I then noticed that Slider dissapeared from menu, which was caused by public -> false. I got it working by changing some values, like show_ui, show_in_menu etc. to true.

    So now I can see it in the admin menu, displaying ok on the homepage and mysite.com/slider/slide-1 returns 404 error. Would this be ok? I also added that code you provided but it still displaying 404 error. I have my custom 404.php. Is this a good solution too, or should I somehow make the redirect work? Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic