How To Hide Categories From The Homepage In WordPress

How To Hide Categories From The Homepage In WordPressPin
In WordPress we have a tool that helps us organize content, so users can find what they are looking for in a faster way.

This tool is the categories, but, we may have too many, and we don’t want to show them all on the main page.

Remember that categories are used to divide our content according to topic. So a category will only show the posts it contains.

On our home page we do not want to show all categories, for many reasons, to make our site more attractive, increase SEO, accelerate loading speed, reducing content.

WordPress will not let us hide categories by default, so we will have to find a solution.

There are two methods to exclude a category, through a plugin, or in a way for more advanced users, the code.

Hide Categories From The Homepage Using Plugin

The first thing we are going to do is go to the WordPress Dashboard and go to the Plugins → Add New. We look for the Category Excluder plugin.
Category Excluder plugin WordPressPin

We install and activate the plugin, and to access its configuration, within the WordPress Dashboard we go to Settings → Category Excluder.
Category Excluder plugin settings WordPressPin

Here we can mark different options, we can exclude different categories, and on the page where we do not want them to load, the main page, RSS feeds, the search …

Once the configuration is finished, click the Update button to save the changes.

Hide Categories From The Homepage Using Code

In this case we are going to add code to WordPress, which is intended for advanced users, although it is not difficult, but we can spoil our WordPress.

To perform this action, we must add the following code to our “functions.php” file.

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

The ID (-1), with the ID of the category that we want to hide. It will hide all the posts that belong to that category of the blog, and that match the ID.

The minus symbol should be kept, since we want to hide that category.

We can also hide more than one category at the same time, simply adding the IDs that we want not to be shown.

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

This is how easy we can remove the categories we want from the home page, so as not to overload our home page, and make it more user-friendly for our users.

If you have not created your website yet, you may be interested Create Your Website With WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *