Family Encyclopedia >> Electronics

How to exclude a category from your WordPress home page

Do you want to exclude a specific category from the main page of your website? By default, WordPress displays posts from all categories on your home page. In some cases, you may not want that. In this article, we will show you how to easily exclude a category from your WordPress home page.

How to exclude a category from your WordPress home page

Why exclude a category from the WordPress home page?

WordPress allows you to sort content into categories and tags. Sometimes you may want to use a category for posts that are not part of your normal blog posts.

By default, WordPress does not allow you to hide posts in specific home page categories or archives. This leaves you with unwanted messages appearing on your home page.

With that said, let's see how you can easily exclude a specific category from your WordPress homepage. We will show you two different methods and you can choose the one that best suits your needs.

Method 1:Exclude a WordPress category using the plugin

The first thing you need to do is install and activate the Ultimate Category Excluder plugin. For more details, you should follow our guide on how to install a WordPress plugin.

Upon activation, you will need to go to Settings »Excluder Category page. It will display all the categories that are available on your WordPress blog.

How to exclude a category from your WordPress home page

From here, you can simply check one or more categories in the "Exclude from first page" column. If you want, you can also exclude the category from RSS feeds, archives, or even from WordPress search.

How to exclude a category from your WordPress home page

Don't forget to click on the Update button to store these settings.

You can now visit your website to see that posts from the selected categories are excluded from the front page.

Method 2:Exclude a category from the WordPress homepage using code

This method requires you to add code to your WordPress files. If you haven't done this before, check out our guide on how to copy and paste code snippets in WordPress.

You will need to add the following code to the functions.php file of your theme or a site-specific plugin.

 función exclude_category_home ($ query) if ($ query-> is_home) $ query-> set ('cat', '-5'); devolver $ consulta; add_filter ('pre_get_posts', 'exclude_category_home'); 

Don't forget to replace ID (-5) with your category ID. It will hide all blog posts from the home page that belongs to the category that matches this ID.

Note: Be sure to add a minus sign (-) with the category ID.

Not sure how to find the category ID? See our guide on how to find category IDs in WordPress.

If you want to exclude multiple categories then you can change the code like this:

 función exclude_category_home ($ query) if ($ query-> is_home) $ query-> set ('cat', '-5, -9, -23'); devolver $ consulta; add_filter ('pre_get_posts', 'exclude_category_home'); 

Simply replace the IDs (-5, -9, -23) with your category IDs to exclude them from your WordPress homepage.

We hope this article helped you learn how to exclude a category from your WordPress home page. You may also want to check out these most wanted category hacks and plugins for WordPress that will help you use categories more efficiently.

If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Facebook.