Why and how to hide category in your WordPress site
Categories in WordPress support 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 category 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 the reasons and methods to hide categories easily in your WordPress website.
Why do 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 to 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, that 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 harm your search engine optimization.
Methods to hide category in WordPress.
There are many ways to hide categories in WordPress, but we would like to provide readers with the easiest ways below:
Method 1: Hide Category in WordPress using plugins
WordPress is a flexible CMS 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:
- 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.
The next step, you visit your website and look for the hidden category on the homepage. However, if you use the steps above, then the specific categories should be hidden on the homepage.
Method 2: Hide Category in WordPress 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, 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 fixes 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
Wrapping Up
There could be a lot of reasons why you would want to hide categories 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 hiding categories in WordPress.
Besides, whether you are looking to build robust e-commerce websites, redesign existing websites, or seek a professional maintenance & support service, our WordPress Development Packages provide you with certified experts who are ready to help you achieve your business goals.
Read More: Free WordPress Theme: Top 25+ Best Themes Compared