How to disable Uncategorized category URL?

I would like to disable the Uncategorized public URL (i.e. /category/uncategorized), since I’m not using post categories and already have the posts list with pagination on the main Blog posts page. Having the Uncategorized category URLs simply creates duplicate pages.

Is there a way to disable post categories entirely until I’m ready to use them? It seems WordPress forces posts to be associated to a category.

In lieu of this, is it a good practice to simply redirect the uncategorized URL in plugin code? For example:

function redirect_uncategorized_category($request) {
  if(array_key_exists('category_name' , $request)
     && $request['category_name'] == "uncategorized") {
       wp_redirect(get_post_type_archive_link('post'), 301); exit;
  } else {
       return $request;
  }
}
add_filter('request', 'redirect_uncategorized_category');

Or I can create a category-uncategorized.php file and force a redirect in there like so:

<?php wp_redirect(get_post_type_archive_link('post'), 301); exit; ?>

Is this the best way?

Thanks.

5 Answers
5

First you need to go in Setting >> Writing. Then, you need to follow below steps.

Step 1: Change Your Default Post Category

Step 2: Delete Uncategorized

It may chance that you may have some posts in Uncategorized category. You just need to transfer those posts to new default category. So, don’t worry your problem will solved.

Leave a Comment