Why and How to Hide a Category in WordPress

WordPress categories allow you to organize your topically-related posts together. This makes it easier for users to browse through your content, as well as making your website and blog look more professional.

By default, WordPress displays all available categories on your blog, homepage or feeds. However, it is not always useful to display all categories on your website – sometimes, you want to hide specific categories for security or privacy reasons.

Let’s look at 5 reasons for hiding WordPress categories, and then introduce 3 common ways to make a category private.

First, why hide WordPress categories?

Below you will find the 5 most common cases in which you want to hide a category:

1. Hiding WordPress categories on the homepage

It may be that you only want to display a specific category on your homepage. In this case, you won’t want to list other categories in your navigation menu.

Let’s take the News category as an example. There are important upcoming events in your company and in the industry – users need to find out about this news and not about other types of content.

In this scenario, it would make more sense to remove all other categories except “News” from the home page. Since the other categories are hidden, users are forced to read the latest news only in the “News” section.

2. Hiding a category on the blog page

Imagine you have several products and each has its own content category. Your blog lists all articles that belong to all categories. However, you are promoting a specific product, so content relating to other products is not displayed and confuses visitors.

The downside of this is that it’s very time-consuming to hide post after post, which is why removing an entire category comes in handy if you want to hide several related posts at once.

Another good example is removing the “Uncategorized” category. If you’ve published some posts in the past that are no longer relevant to the content of the website, it’s a good idea to hide them from the blog so that users are not confused by irrelevant topics.

3. Hiding a category on the author page

Each author on your site may have expert knowledge in a specific niche. For this reason, the website needs multiple authors who focus on different areas of their business. Some of them only write standard content, while others write premium content.

Not all visitors are entitled to see both types of content. Premium authors should be hidden on the “Author” page. By excluding them, all posts written by these authors will no longer be displayed.

4. Hide a category from the WordPress search

Readers on your site may find articles via the search box, so removing less important categories provides users with a shorter list of results. In addition, these results are more relevant to the search query. This creates a better experience for users and improves the usability of your website.

5. Hiding a category from RSS feeds

RSS – “Rich Site Summary” – includes simple text files that contain basic updated information about a website such as news or articles.

There might be a content category that you do not want to appear in the feeds. Therefore, it is necessary to exclude it from the RSS feeds of your WordPress website.

So, we’ve gone through some key reasons why you may want to hide a category on your website. And actually, it’s really easy to hide a page or post with the standard WordPress “Private Page Visibility” feature.

However, removing an entire category is sometimes difficult for beginners. Let’s look at 3 solutions below: hiding a category manually, password protect it with the PPWP Pro plugin, or create access levels using the Access Level extension.

Make a WordPress category private manually

This method requires you to add code to the functions.php file of your WordPress theme. To exclude a category from being displayed on your blog page or homepage, perform these 2 major steps manually:

Step 1: Determine the category ID

  • In your WordPress admin dashboard, go to Post → Categories
  • Hover the mouse pointer over the title of the desired category
  • Access the category ID number via the link at the bottom of the screen
hide-category-manually

Step 2: Edit the theme file

Next, go to Appearance → Editor.

appearance-editor

Then, select the theme you are using from the drop-down list, and click on the functions.php file.

edit-php-file

Paste the following code at the end of the file;

function exclude_category($query) {
   if ($query->is_home() && $query->is_main_query()) {
       $query->set('cat', '-31');
   }
}
add_action('pre_get_posts', 'exclude_category');

There are 2 things to note about this:

  • The number “31” in the third line refers to the ID whose category you want to hide
  • The minus sign “-” (minus) means that this category should be excluded

You can also exclude several categories at once by inserting their category IDs into the brackets in the third line and separating them with commas. For example:

function exclude_category($query) {
   if ($query->is_home() && $query->is_main_query()) {
       $query->set('cat', '-31, 15, 20');
   }
}
add_action('pre_get_posts', 'exclude_category');

How to remove a category from the loop

It is also possible to remove a category from the loop. Insert the following code snippet into your functions.php file:

/**
* Exclude certain categories from the WordPress loop
*/
add_action('pre_get_posts', 'exclude_specific_cats');

function exclude_specific_cats($wp_query) {
   if (!is_admin() && is_main_query() && is_home()) {
       $wp_query->set('cat', '-31, 15');
   }
}

Removing a category programmatically requires technical knowledge. You also have to remember each ID if you remove several categories at once. This is where a third-party plugin comes in handy.

There are a number of plugins that can solve this problem. PPWP Pro and its Access Level extension stand out from the crowd with their powerful features and user-friendly interface.

Protect the WordPress category with the PPWP Pro plugin

Password Protect WordPress (PPWP) Pro effectively secures your WordPress categories with passwords.

Get started with the following 4-step guide:

  1. Install and activate PPWP Pro. The Pro version does not work without the Free version. So remember to install the free version first.
  2. In your WordPress dashboard, go to Posts → Categories
  3. Select the desired category
  4. In the “Password protection” column, click on the “Protect” category to quickly protect it with a password
password-protect-categories

Once the category is password protected, all posts in this category are invisible to the general public. Users must fill out a password form if they want to access your category page or posts in this category.

Each article in your category will be assigned a different password. When a post in the category is unlocked, this means that your category is now unprotected. However, other articles will still display a password form when users try to access them.

With this Pro plugin you can do even more. It is possible to hide the protected content from search indexing. In other words: Your category page and all posts below it will not be displayed in the search results.

blog-search-indexing-ppwp

In addition, you can protect the entire WordPress website with just a single password. Last but not least, you can also use the plugin to exclude some pages from site-wide protection.

You can watch this video to illustrate the instructions.

Secure WordPress categories by level

With the PPWP Pro plugin, you can only protect content categories. The Access Levels addon extends the possibilities by protecting product categories and assigning them different authorization levels.

First you need to download the PPWP Access Levels extension. This adds an additional section to the WordPress Password Protection menu in your sidebar. Click Access Levels to start protecting your categories.

ppwp-access-levels

You will need to go through a 3-step process to successfully hide your WordPress categories by level.

Step 1: Create a base

After clicking on Access Levels in the main menu, you will be redirected to an access level management screen. Click on the Add new base button, which will open a pop-up window where you can add a base name.

Step 2: Select categories and organize them into levels

With the Edit levels option in the Actions column, you can select the post types to be protected. These can be posts, products or any other user-defined post type.

It is now time to set the levels of your categories. Level 2 will have a higher authorization than level 1. In the following example, users who enter passwords for posts in the “Media” category will also unlock the “Edge Case” category.

Step 3: Create passwords for access levels

Switch to the next tab of “Add new password”. Enter your password and the associated information such as levels, type (global or user roles), usage limit and expiry time.

You can edit your passwords by going back to the Manage passwords tab. Here you get an overview of all your passwords and their status.

This is what your category page looks like if you have assigned passwords to them via the PPWP Pro plugin and the Access Level extension.

You now have full control over the management of your private content. This saves you time when hiding individual categories. Different user types have different access rights to content.

While Premium members can open all categories at once, Standard members only have the right to see a few category contents.

Conclusion

Categories are useful for grouping content in all WordPress websites. When it comes to hiding a category, there are several options available to you, either by technically inserting code or by installing a plugin.

Firstly, you can manually insert code into the functions.php file of your theme to hide categories. However, the challenge lies in the technical programming knowledge you need to have to use this method.

Instead of using code, you should take advantage of plugins if you are not familiar with technical knowledge. With PPWP Pro and its Access Level extension, you can hide categories from the home pages. Only those with the right passwords will be able to see their posts.