How To Hide or Remove Categories from the Homepage on WordPress

Most of the WordPress websites show the latest posts on the homepage. The reason behind it is the desire of most of the users to see the new articles being featured there. The recent content are being classified into several categories. However, there are times when you don’t want to see some of them. For the beginners, it might look impossible to do. But in reality, it can be done pretty easily. In this article, you will find different ways to excluding categories from the homepage on WordPress website.

Modifying the functions.php File

The loop is the code the WordPress uses to display the content on the website. Every WordPress theme makes the use of it. You can modify it to exclude specific categories on the homepage. Here are the steps:

Step 1:

Go to our functions.php file

Step 2:

If you have two categories of post (uncategorized ‘3’ and another ‘1347’), add the following codes there:

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

Here ‘3’ and ‘1347’ are IDs. If you are facing trouble to find them, use the following method:

Finding Category IDs

Step 1:

Navigate to Posts > Categories.

Step 2:

Put the cursor on your desired category.

Step 3:

Take a look at the number beside category&tag_id within the destination page URL. It is your category ID.

How To Hide or Remove Categories from the Homepage on WordPress

Using Ultimate Category Excluder

Ultimate Category Excluder is a popular plugin for removing categories from the home page. The method of exclusion is very easy. You just need to select the categories that you want to remove. It can be very useful if you are not comfortable with editing the files of your WordPress theme.

How To Hide or Remove Categories from the Homepage on WordPress

There is an issue with Ultimate Category Excluder. Right now, you cannot use the plugin to remove Categories from Category Widget. But if you really need to do it, you have to modify your theme’s function.php file. The codes look quite similar to the ones mentioned in the second step of Modifying WordPress Loop.

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");

Conclusion

In this article, you have seen two different ways of hiding or removing categories from your WordPress homepage. Right now, most of the users prefer to use Ultimate Category Excluder. However, if you have no issues dealing with codes, you can follow the first way to exclude categories pretty easily.

Check out these top 3 WordPress hosting services:

Was this article helpful?