Are you looking for a way to hide a specific category from your WordPress homepage? By default, this CMS displays posts from different categories on the homepage.
If your website focuses on Blogs, this is fine. However, in other cases, this may not be necessary and in some cases purely annoying.
In this article, we would like to discuss how to hide the category in WordPress with 4 easy methods.
Why Hide Category in WordPress?
By default, WordPress allows you to sort the content on it into different categories and tags. Sometimes you may want to create a WordPress category that users can’t have access to. Thus, you have to hide the category.
Unfortunately, WordPress won’t let 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 pretty simple task. Below, we will explain a few methods. Hopefully, by following the steps carefully, you can hide the specific category from the WordPress homepage.
Keep in mind, if you hide categories by changing the display: none code in the CSS files, you will receive negative points from search engines and it will have a negative effect on your SEO.
How to Hide Category in WordPress?
WordPress is a flexible website builder and there are thousands upon thousands of plugins you can choose from to add extra functionality to your website.
To hide category in WordPress we’re going to use the Ultimate Category Excluder plugin. To use this plugin, follow the steps below:
- Go to Plugins > Add New
- Search for ‘Ultimate Category Excluder‘, Install and Activate it
- Go to Settings > Category Excluder.
- Checkmark the categories you want to hide.
- Click on Update
Now visit your website and look for the hidden category on the homepage. If you have followed the steps above, then the specific categories should be hidden on the homepage.
How to Remove Category from Widget?
If you primarily want to hide the category in WordPress widget, you can do so by downloading the WP Categories Widget plugin. Currently, this plugin has 5 stars with over 3000 active installations. In addition, this plugin works with PHP versions 5.3 and above and it’s compatible with the latest version of WordPress.
What are the features?
This plugin comes with many features like:
- The ability to show categories of any taxonomies type
- The ability to hide widget title
- The ability to show categories post count
- The ability to show or hide categories
First, download, install and activate the plugin. Once the plugin is activated, from the Appearance menu in the WordPress Dashboard click on Widgets.
Then, simply drag and drop the installed plugin to your sidebar, or footer.
Then you have the option to rename the title, hide the title, hide count. In addition, from the Show, All Category drop-down menu select which categories to hide or display.
Once you are done make sure to save the changes.
This is everything you need to do to hide the category in WordPress widget.
Hide Category in WordPress using Code
Other than the methods mentioned above, by adding a piece of code to WordPress, you can hide a category from the homepage.
However, this method is a bit different and could be complex for some WordPress users. Therefore, if you don’t have any programming knowledge, we recommend using the plugin mentioned above.
Before we begin, it is highly recommended that you fully backup your WordPress website. In case anything goes wrong so you can fully restore your website back to its original state.
As mentioned above, there are many reasons to hide a specific category in WordPress. You may want to keep your website’s homepage neat and only for important posts.
In this method, we are going to make some changes to the WordPress loop. All WordPress themes use the loop and the best way to modify this loop to hide categories is by using the pre_get_posts hook.
Once again, if you don’t have any programming knowledge, we recommend using the methods mentioned above. Hiding categories from the homepage can be a bit challenging for beginners.
With an FTP client or hosting panel, connect to your website and go to wp-content/themes and open the activated theme folder. Locate the functions.php file and download it in your computer.
Open the file with an editor like Notepad++ and add the following code to the file:
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-5' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category_home' );
In the $query->set( ‘cat’, ‘-5’ ); you have to replace “-5” with your category ID. To find your category ID, follow the steps below:
- Login to WordPress Dashboard
- From Posts menu click on Categories
- Hover over the category you would like to hide
- At the bottom of the page you can see the URL and ID
Look at the image below:
For example, the ID for Countries category is 6. Therefore, replace -5 in the code with 6 and save the file and upload where you downloaded it from.
Once again, this method may be difficult for beginners. In addition, some hosting providers may not give you permission to access your root directory. If you are amongst those people and still want to use this method to hide a specific category from the WordPress homepage, follow the steps below:
- Login to WordPress Dashboard
- From Appearance click on Theme Editor
- Select your theme on the right-hand side above the Theme Files
- From Theme Files look for functions.php and click on it
- Copy and paste the code mentioned above somewhere in the file and click on Update
Make sure you remember where you have added the code so you can replace the -5 value in it with the actual category ID.
Hide Category in WordPress Based on User Roles
There is also a way to hide categories in WordPress for a specific user role. For example, this method is very useful if you have premium content that you only want the premium users to have access to.
In this method, we are going to use the CaPa Protect plugin. This plugin may be old but it’s still effective and compatible with the latest version of WordPress. However, you have to manually edit one user at a time.
First, 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:
Once you are done, make sure to click on Update User.
2 Comments Leave a Reply
Hey i only want to hide category name from products section as i have many products that is also included in many different categories so if all the categories are visible it looks so bad so how to do that
I suggest you write some CSS code to hide those elements in the pages you want. A more gig method is editing PHP codes but the CSS method can be done in less than 5 minutes!