How to disable the single view for a custom post type?

Question

I created a custom post type:

register_post_type('sample_post_type',array(
    'labels' => array(
        'name' => _x('Sample Posts', 'post type general name'),
        'singular_name' => _x('Sample Post', 'post type singular name')
    ),
    'public' => true,
    'show_in_nav_menus' => false,
    'exclude_from_search' => true
));

How can i disable the single post view for this specific post type? Displaying a simple 404 is fine, or redirecting to the homepage. This is inside a plugin, so i can’t create a single-sample_post_type.php file to setup an empty page.

0
, passatgt 3 years 2020-04-07T00:51:03-05:00 0 Answers 125 views 0

Leave an answer

Browse
Browse