How to Exclude Categories from the WordPress Homepage (3 Different Methods)

Last updated on
Feb 21, 2024

In most WordPress themes, every newly published article is displayed on the homepage, regardless of its category. For a certain reason, you might want to exclude articles from certain categories from being displayed on the homepage.

It’s very rare to find a WordPress theme that has a default feature to exclude articles from the homepage. If you really want to do so, we will show you three different methods to exclude articles from certain categories from your site homepage.

Method 1: By Adding a New Function

The first method to exclude articles from your site homepage is by adding a new function to your theme. This method requires the IDs of the categories you want to exclude. To find the ID of a category, you can go to Posts -> Categories. Edit the category you want to check its ID by clicking the Edit link.

Once you are on the editing page, go to the address bar on your web browser. Your category ID is the number right after the tag_ID text (marked with yellow)

Once you get the IDs of the categories you want to exclude, go to the Appearance -> Theme Editor. Click the functions.php file on the right sidebar to edit it.

Add the following code. If you have no idea where to place the code, simply place it on the bottom side. Don’t forget to click the Update File button after adding the code below. Also make sure to tailor the IDs of the categories.

function hide_category($query)
{
if ( $query->is_home )
{
$query->set('cat', '-25,-112'); //category ID
}
return $query;
}
add_filter('pre_get_posts', 'hide_category');

Method 2: Using a Plugin

If dealing with PHP code is something scary for you, there is a plugin as a solution to exclude categories from your site homepage. One of the plugins that you can use is Ultimate Category Excluder. It’s a free plugin that you can get on the WordPress plugin directory. Simply install and activate the plugin to use it. New to WordPress? You can read our previous article to learn how to install a WordPress plugin.

Once the plugin is installed and activated, go to Settings -> Category Excluder on your WordPress dashboard. On the Exclude from Front Page? column, tick the categories you want to exclude and click the Update button.

Method 3: Creating a Custom Homepage

Another option to exclude categories from the homepage is by creating a custom homepage. You can use a page builder plugin like Elementor, Divi Builder, or Brizy to do so. In this article, we will show you how to create a custom homepage using Elementor.

Elementor has a widget — the Posts widget — that you can use to display the blog posts on your website. You can filter the blog posts by categories, tags, authors, and so on. The Posts widget itself is only available on the pro version of Elementor. In other words, you need to use Elementor Pro to be able to use the widget. Once you are ready, create a page (Pages -> Add New) and edit it with Elementor by clicking the Edit with Elementor button.

In this article, we will go straight to adding the Posts widget. Simply drag the Posts widget to the canvas area.

Go to the settings panel on the left side to make the settings. To filter the posts, you can open the Query block under the Content tab. On the Source option, leave it to default (Posts). Click the EXCLUDE tab. On the Exclude By field, set to Term and then select the categories you want to exclude from the appearing field.

Once you are done editing your page, publish it by clicking the PUBLISH button on the bottom side of the settings panel.

Once your custom homepage is published, the next step is to set it as the homepage on your WordPress site. To do so, go to Settings -> Reading on your WordPress dashboard. On the Your homepage displays section, set to A static page option and select the custom homepage you have just created above from the dropdown menu. Click the Save Changes button to apply the change.

This page may contain affiliate links, which help support the project. Read our affiliate disclosure.

Editorial Staff

Want to build passive income with your blog? You need these resources, then.

Where should we send the template?

Thanks! Please check your inbox to confirm.