I've created a few Custom Post Types for my site. And some of them shouldn't have a viewable page in the front-end.
I saw, that there is an argument to prevent archives for Custom Post Types:
'has_archive' => false,
Is there anything like this for single front-end pages?
At the moment I create a 301
redirect for these Custom Post Types:
add_action( 'template_redirect', 'theme_redirects', 99 );
function theme_redirects() {
if ( is_singular( 'post_type' ) ) {
wp_redirect( home_url(), 301 );
die();
}
}
But for me, that's not an ideal situation.
Is there anything I could do instead of the redirects?
You can make use of the publicly_queryable
option. It's the same as the has_archive
option, but for single posts.
Simply add this to your CPT config:
'publicly_queryable' => false