Remove or Hide Categories Option from the Homepage in WordPress

Remove or Hide Categories Option from the Homepage in WordPress

If you’ve worked on WordPress websites, then you’d know that by default, WordPress displays recent posts and categories on its homepage. The reasoning behind this is people coming to the website would perhaps like to read the latest posts or browse the categories by themselves.

While it may work well for certain websites and blogs, this style of presentation is irrelevant for others. So you might be wondering how you can remove or hide the categories option from the homepage of your WordPress website. In this article, learn the exact process for that.

Step-by-step Process

Here are the steps you need to take:

Open the functions.php file

Add the following codes in it:

function exclude_category_home( $query ) {if ( $query->is_home ) {$query->set( 'cat', '-5, -2441' );}return $query;}add_filter( 'pre_get_posts', 'exclude_category_home' );

In the above code “5” and “2441” are category IDs. You need to add more IDs if you’ve got more categories.

If you don’t know what’s the ID for the categories you have, here’s how to find them:

Open Posts>Categories

Focus the cursor on any category

Now look at the bottom of the screen where the destination URL will be displayed once you hover on it

Take note of the tag_id. That’s the ID for that particular category

Once you’ve added the code with the required category IDs, the website will no longer display categories on the home page.

Use the Ultimate Category Excluder Plugin

Instead of going through the above process, you can use a plugin instead. The Ultimate Category Excluder Plugin is a popular one that gets the intended job done.

So install it to start using it. Once installed, open it and you’ll see a bunch of options. You’ll see a list of categories and the options to hide them from the main page, feeds, or archives.

But it has a limitation. The plugin cannot hide categories from the Category Widget. For that, you need to open the function.php file and include the following code:

function exclude_category_widget($args){ // Add the category IDs you want to exclude, separated by commas $args["exclude"] = "-3,-1347"; return $args;}add_filter("widget_categories_args","exclude_category_widget");

So that’s how you hide the categories. For further assistance, contact the customer support.
Author
kumkumsharma
Views
2,497
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top