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.

  • 1
    Do you want the categories active for organisation on the back end of the website, but not active on the front end? Might help to add a little more detail to your problem. – Chris Morris Sep 9 '14 at 9:32
  • @ChrisMorris, did the update help? And... It is ok if the category pages are not accessible at the backend .... – Tabrez Ahmed Sep 9 '14 at 9:49
  • Reading your other posts gave a bit of clarification. Though I'm unsure as to the end goal you're after. What is it that you're trying to build? – Chris Morris Sep 9 '14 at 9:53
  • @ChrisMorris, Hope the update to the question answers your question. – Tabrez Ahmed Sep 9 '14 at 10:20

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

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

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

  • editing wp files is not what I am allowed to . . . . – Tabrez Ahmed Sep 9 '14 at 9:52
  • Hope the update to question helps . . . – Tabrez Ahmed Sep 9 '14 at 9:52
  • category.php is a theme file, not a core file. (assuming that's what you mean by "wp files") – totels Sep 9 '14 at 9:56
  • Oops, sorry. But I thought I'd implement a cross-theme solution. – Tabrez Ahmed Sep 9 '14 at 10:24

You'll need to do at least two things (possibly more, I haven't thought it all the way through), in it's simplest form:

  1. Prevent category output lists from creating links:

    You'd need to emulate get_the_category_list() and build your own category list without anchors, or you could probably just filter out the <a> tags:

    add_filter( 'the_category', function ( $thelist, $sep, $parents ) {
      return strip_tags( $thelist, '<ul><li>' );
    } );
  2. redirect category URLs somewhere.


    <?php wp_redirect( home_url() );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.