How to disable access to category pages

I want my categories to be active and at the same time I want to make the category pages inaccessible. Is it possible? If yes, How?

Why I want to do this? (Possibly this may help)

I am working on a ugc website. I am asked to bring /category/cat-name to /cat-name. I am also asked to add another page /cat-name/add where users are allowed to post only to a specific category. It is not possible to add page /cat-name/add until I create a page (not category page) /cat-name. If I create a page /cat-name, it’ll conflict with the category page /cat-name. This is why I thought I’d disable category page /cat-name and use a normal page at /cat-name to list category posts.

2 Answers
2

You can add something like this in your category.php.

if ( ! is_admin() ) {
     wp_redirect( home_url() );
     exit;
}

This will redirect viewers to website homepage but category pages will be active and accessable to admins only.

Leave a Comment