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.

Topic wp-redirect categories posts Wordpress

Category Web


Instead of deleting the "Uncategorized", i.e. default post category, one should rename it as defined here. Or any generic category name that can be matched with the niche of the blog/website.

Link: https://www.wpdeveloper.xyz/beginners-guide/rename-the-uncategorized-category-on-your-wordpress-blog/


if((get_the_category_list() !== 'Uncategorized')){
                            the_category();
                        }

Categories is a core feature for organizing Posts, providing users with a searchable, context-aware, and relational user experience.

Rather than trying to modify the taxonomy itself, modify the view. Comb through your site's widgets and menus and remove any filters or widgets that display Posts based on Categories data. For example, modify Default Sidebar at yoursite.com//wp-admin/customize.php by removing the Categories widget.

This approach leaves the door open for you to add Categories where it makes sense later on. Consider whether Pages might better suit your needs, as they assume a more fixed organization.


You can't remove the last category. If you wish to remove the categories from the default post type, you can use the remove_post_type_support() function:

add_action( 'init', 'remove_categories_from_posts' );
function remove_categories_from_posts() {
    remove_post_type_support( 'post', [ 'taxonomy' => [ 'category' ] ] );
}

This is untested, but it should do the trick.

There is another question about this on the StackOverflow which might be useful for you.


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.