0

I am trying to disable the archive page and the single page for the default post type 'post'.

So far I have tried multiple methods:

function my_func() {
    if ( post_type_exists( 'post' ) ) {
        global $wp_post_types;
        $wp_post_types['post']->publicly_queryable = false;
    }
}
add_action( 'init', 'my_func', 99 );

function change_default_post(){
    $post_type = 'post';
    $post_type_object = get_post_type_object('post');
    $post_type_object->has_archive = false;
    $post_type_object->public = false;
    $post_type_object->publicly_queryable = false;

    register_post_type($post_type, $post_type_object);
}

add_action( 'init', 'change_default_post' );

function change_default_post(){
    $object = get_post_type_object('post');
    $object->has_archive = false;
    $object->public = false;
}

add_action( 'init', 'change_default_post' );

But nothing seems to work. Any ideas?

3
  • Have you tried the code from this answer? redirecting when someone tries to visit either of these pages
    – kero
    May 15, 2018 at 14:53
  • It would be simpler to simply remove permissions to create posts from all users, then you won't have anything post-related accessible from the front or back end. Any particular reason you're trying to modify the actual post type? May 15, 2018 at 16:42
  • I have a theme with demo content posts. I have already modified it with a child theme, and the role that the posts have are now replaced with a custom post type. I am currently testing the WP Super Cache plugin (preloading pages) and just realized how many post types have single pages enabled, that i don't need. It's not a problem disabling them for my or the theme-s custom post types. The question is: if I use a redirect or just delete all demo posts, and disable adding new 'post' posts, will WP Super Cache still cache a page?
    – D. Dan
    May 16, 2018 at 6:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.