by NganNT
January 14, 2022

Why and how to hide category in your WordPress site

Categories in WordPress supports you organize content to make it more convenient for users to find out what they’re looking for. However, not all of them need to be showcased on the homepage. This is especially necessary if you have a very long list of them. What if you need to hide categories from the homepage in WordPress? This task may help keep the main page of your website clean and even more organized. In this tutorial, we’ll show you reasons and methods to hide category easily in your WordPress website.

Why you need to hide Category in WordPress?

In the WordPress default, you can easily sort the content on it into different categories and tags. Also, sometimes you may want to generate a WordPress category that visitors can’t have access to. Thus, you have to hide the category.

However, WordPress won’t allow you hide categories from the homepage or archives and it will keep showing the category and its posts on the homepage.

Hiding a category in WordPress is a very simple task. However, keep in mind, if you hide categories by changing the display: none code in the CSS files, you will get negative points from search engines and it will have a negative effect on your search engine optimization.

Methods to hide Category in WordPress.

Method 1: Hide Category in WordPress using Plugin

WordPress is a flexible website builder and there are a lot of plugins you can choose e from to include extra functionality to your website.

  • To hide category in WordPress, simply move to use the Ultimate Category Excluder plugin.
  • To use this plugin, follow the steps below:
hide category wordpress
  • Move to Plugins > Add New
  • Search for ‘Ultimate Category Excluder‘, Install and Activate it
  • Move to Settings > Category Excluder.
  • Checkmark the categories you want to hide.
  • Click on Update
hide category wordpress

Next step, you visit your website and look for the hidden category on the homepage. However, if you used the steps above, then the specific categories should be hidden on the homepage.

Method 2: Hide Categories From The Homepage Using Code

In this case we are moving to add code to WordPress, which is intended for advanced users, although it is not hard, but we can spoil our WordPress.

To perform this action, simply add the below code to our “functions.php” file.

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-1' );
}
return $query;
}

add_filter( 'pre_get_posts', 'exclude_category_home' );

The ID (-1), with the ID of the category that we want to hide. It will hide all the posts that belong to that category of the blog, and that fix the ID. The minus symbol should be kept, since we need to hide that category.

We can also hide more than one category at the same time, simply adding the IDs that you want not to be shown.

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-1, -2, -3' );
}
return $query;
}
  
add_filter( 'pre_get_posts', 'exclude_category_home' );

This is how easy we can remove the categories we want from the home page, so as not to overload our home page, and make it more user-friendly for the visitors

Method 3: Hide Category in WordPress Based on User Roles

There is also other way to hide categories in WordPress for a specific user role. For instance, this method is very helpful if you have premium content that you only need the premium users to have access to.

In this way, you need to use the CaPa Protect plugin. This plugin may be old but it’s still useful and compatible with the latest version of WordPress. However, you have to manually edit one user at a time.

  • First step , you need to download, install and activate the plugin. Then go to the login to the WordPress Dashboard.
  • In the Users tab, click on All Users and select the user you would like to edit.
  • Once you are in the editor, scroll down until you see the CaPa User Settings option.
  • Here, you can hide or show categories and pages from this user.

Look at the image below:

hide category wordpress

Once you are done, ensure to click on Update User.

Wrapping Up

There could be a lot of reasons why you would want to remove certain categories from the homepage in WordPress. Whether they are empty or you just have too many different factors, it’s all about keeping the website clean and user-friendly. Arrowtheme hopes you will encounter no issues while hide category WordPress.

Besides, whether you are looking to build robust ecommerce websites, redesign existing websites, or seeking a professional maintenance & Support service, our WordPress Development Packages provide you with the certified experts who are ready to help you achieve your business goals. 

Especially, you can get up to 30% off for all of your WordPress services. You can reach us at Here. We’ll be happy to provide you with a free consultation

0 comments

Related Posts