2

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.

0

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.

  • Thanks for your reply, but this does not solve my question. This only changes the default category that posts are associated to and then I can't delete that category. What I would like to do is remove all categories. – Ralph Feb 13 '18 at 15:04
  • You can remove that category also by hacking the code. But, it is not proper way. You should not delete all categories. You can exclude it but should not delete it. – Harsh Barach Feb 13 '18 at 15:15
0

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.

0

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.

-1
if((get_the_category_list() !== 'Uncategorized')){
                            the_category();
                        }
  • This method will not work, the function returns the category list in HTML format (<ul><li></li></ul>). Look at this example. – nmr Aug 7 at 9:34
  • Yes, it returns the ul li. But with this method, you get all the posts' categories as well as prevent it from displaying the "Uncategorized" category. – Farzad Jafari Aug 7 at 9:50

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.