hide-category-wordpress

Can You Hide a Category in WordPress?

WordPress category offers one of the most convenient ways to organize related posts which makes it easier for users to scan through your content. Your website will look more professional as well.

By default, WordPress displays all available categories on your blog, homepage, or feeds. In fact, it isn’t always appropriate to have every category shown up on your site. You sometimes want to hide specific categories for some reasons.

In this post, we’ll list out 5 reasons for hiding WordPress categories and put together 3 common ways to make a category private.

Why Hiding WordPress Category?

As a WordPress site owner, you might want to privatize or unlist a category for some reason. Following are the 5 most popular cases where you would like to hide a category from:

1. Hide from the Homepage

There might be times you intend to display a specific section on your homepage only. Then, other categories won’t be listed on the navigation menu.

Let’s take the News category as an example. There are important upcoming events in your company as well as the industry. Users must keep up with this news instead of other types of content. Then, leaving all other categories except the News off the homepage would make more sense. Since other categories are hidden, users are allowed to read the latest news in the News section only.

2. Hide a category from the Blog page

Your blog lists out every article belonging to all categories. You’re focusing on a specific product so content related to others shouldn’t show up and confuse the visitors. However, it takes a lot of time to hide post by post. Removing a whole category proves convenient to hide multiple related posts at a time.

3. Hide a category from the Author page

Each writer has expert knowledge of a specific niche. That’s why each site requires several authors to focus on different areas. Some of them just write standard content while others provide premium posts only. Not all visitors are authorized to view both types of content. Premium writers should be hidden from the Author page. Once excluded, all posts written by these authors won’t show up anymore.

4. Hide a category from WordPress search

Readers often find articles through the search box. Removing less important categories offers users a shorter list of results. What’s more, these results would be more relevant to the search query. This creates a better experience for users and improves your website’s usability.

5. Hide a category from RSS Feeds

RSS – “rich site summary” includes simple text files which provide basic updated information on a website such as news or articles. There could be a content category that you don’t want to appear in the feeds. So, it’s necessary to exclude it from the RSS feeds on your WordPress site.

You’ve known where to hide your category from. The question turns to how you make a category private now.

It’s really easy to make a page or post hidden with the WordPress Private Page Visibility default feature. However, removing an entire category sometimes turns out to be quite frustrating for beginners. Let’s take a look at the 3 solutions listed below to help put your mind at ease: manually hide a category, password protect it with a plugin, or using a category excluder.

Make WordPress Category Private Programmatically

This method requires you to add code to your WordPress theme’s functions.php file. In order to exclude a category from displaying on your blog page or homepage, manually take these 2 big steps:

Step 1: Get the category ID

1. Head to PostCategories in your WordPress dashboard
2. Hover on the title of the desired category
3. Get its ID number in the link at the bottom of the screen

hide-category-manually

Step 2: Edit the theme file

4. Go to AppearanceEditor
5. Select the theme you’re using from the dropdown
6. Click on the functions.php file
7. Add the following lines of 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 keep in mind:

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

appearance-editor

edit-php-file

You can also exclude several categories at a time by adding 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’s possible for you to remove a category from the loop as well. Place the following code snippet in your functions.php file:

/** Exclude Specific 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 every ID whenever removing multiple categories at a time. That’s where a third-party plugin comes in handy. There are a number of plugins capable of handling this concern, including password protection plugin for categories and category excluder plugin.

Hide WordPress Category with Password Protect WordPress Pro Plugin

Password Protect WordPress Pro provides an effective method to secure a WordPress category with a password. In order to password protect a category, take the following 4-step guide:

1. Install and activate Password Protect WordPress Pro. The Pro version won’t work without the Free version so remember to install the Free version first.
2. Go to PostsCategories in your WordPress dashboard
3. Select the desired category
4. In the Password Protection column, click on the Protect category to quickly password protect it

password-protect-categories

Once password protected, all posts under the category become invisible to the general public. Users have to fill in a password form whenever accessing your category page or any posts belonging to that category.

You can do even more with this Pro plugin. It’s possible for you to hide the protected content from search indexing. In other words, your category or all posts under it won’t be shown in search results.

blog-search-indexing-ppwp

On top of that, you can make the entire WordPress site private with just a single password. Last but not least, the plugin enables you to exclude some pages from the site-wide protection too.

Hide WordPress Category with Ultimate Category Excluder Plugin

Ultimate Category Excluder offers WordPress site owners an effective solution to remove WordPress categories from the front page, archives, feeds, and searches. All you need to do condenses into these 5 simple steps:

1. Go to PluginsAdd new
2. Search for Ultimate Category Excluder in the search box
3. Click Install then Activate the plugin

install-category-excluder

4. Head to SettingsCategory Excluder page which lists out all your available the categories
5. Check one or several categories under the Exclude from front page column. You can exclude the category from RSS feeds, archives too.

category-excluder

Ready to Hide Your WordPress Category?

Categories are compulsory and of great significance to group content in all WordPress websites. When it comes to removing a category, there are different options for you to choose from, either technically inserting code or installing a plugin.

Firstly, you can manually add code to your theme’s functions.php file to hide categories. However, the challenge lies in technical programming skills you must have to apply this method.

Secondly, use a plugin in case you’re not familiar with technical knowledge. Both Password Protect WordPress Pro and Ultimate Category Excluder allow you to hide categories from the front page, archives, feeds, and searches. The first plugin is more useful as you’re able to make the private categories accessible to anyone who has the correct password.

Install Password Protect WordPress Pro to hide your WordPress category today!

Leave a Reply

Your email address will not be published. Required fields are marked *