How to Hide/show Categories in WordPress
WordPress category is a method to group posts related to each other and display them on your website. Also, It enables you to easily organize content for visitors to see what they are looking for. WordPress does not show empty categories. However, someone may want to show empty categories on their website, while some hide empty ones. This article helps you understand How to Hide/show Categories in WordPress.
How to show category in WordPress
For showing the empty categories in WordPress, You have to add the code to your theme function.php file or a site-specific plugin.
function wpb_list_categories() { // define category list parameneters $args = array ( 'echo' => false, 'title_li' => '', 'hide_empty' => 0 ); // get categories list $display_cats = wp_list_categories($args); //display custom categories list return $display_cats; } // create shortcode add_shortcode('custom_categories_list','wpb_list_categories');
With this code, you can show an empty category. Then, you can display your custom categories using a shortcode [custom_categories_list] in your widget area.
After that, save your settings to see the update.
How to hide category in WordPress
For hiding the categories from your category list, you can modify the above code accordingly.
function wpb_list_categories() { // define category list parameneters $args = array ( 'echo' => false, 'title_li' => '', 'exclude' => '12,16,21', 'hide_empty' => 0 ); // get categories list $display_cats = wp_list_categories($args); //display custom categories list return $display_cats; } // create shortcode add_shortcode('custom_categories_list','wpb_list_categories');
The above code hides the unwanted categories. Further, if you want to hide more, you have to provide the IDs of the categories you wish to exclude.
Using Ultimate Category Excluder plugin
The Ultimate Category Excluder plugin in WordPress excludes a category from the homepage.
First, Install and activate Ultimate Category Excluder.
Go to settings >> click Category Excluder.
You can select the category you want to show and uncheck the category you wish to hide.
Now, Update the changes. You can see the categories you unchecked are hidden.
To cut it short- In WordPress, categories are a great way to group posts that are related to each other and show them on your website. This guides visitors to find the topics they are interested in so that they can stay longer on your site.
Some websites may want to hide empty categories or some want them to show up. I hope this article helped you know How to Hide/show Categories in WordPress. You can use the coding method or use the Plugin method instead.