Hide Post Category from WordPress Homepage

Hide Category from homepage wordpress

In this tutorial I will show you the proper steps to hide certain category posts from appearing on your homepage, index page, or blog roll. If you own a blog and you want to keep posts of a certain category from showing up on your homepage blogroll, but still want them to appear on your website somewhere else, this tutorial will show you how to remove those posts from showing up in the blogroll or homepage.

Before I begin, you are responsible for your own edits to your website, I am not liable for any issues that may come of you doing this. In doing this tutorial it is at your own risk and I am not responsible if you screw something up. This code has worked for me on multiple WordPress websites. If you are a beginner and/or have no coding experience I do not recommend that you do this yourself. With that said, let’s begin…

Step 1

The first step is to navigate to your theme folder, find your index.php file (or which ever file you want to hide the category from appearing), and open it in your text editor.

WordPress index.php

Step 2

Once you have it open in your text editor, locate the start of the loop. It may look different depending on what theme you have and depending on who coded the theme. Below I have 2 different examples pictured, the highlighted area is the loop.

Ex 1)

WordPress Loop

Ex 2)

The WordPress Loop

Step 3

Once you have successfully located The Loop, make a few lines of space above it so there is room for the “hide category” code snippet.

Now that you have made some space, you will need to copy the code below and paste it right above The Loop.

<?php query_posts($query_string . '&cat='); ?>

It should then look like the picture below, the code snippet right above the loop.

Hide Category Code Snippet

Step 4

You’re not done yet, now you will need to tell WordPress which categories you want it to hide from the index page. Once you decide which categories you want hidden from the index.php page, you will need to find the ID of the category(s). To do this, navigate to the categories page in the WordPress admin.

Category Menu WordPress Admin

Once you get there, click the category link you want hidden and view the link info in your browser status bar. It should look something like this: edit&taxonomy=category&tag_ID=5&post_type=post

Where it says ID=5 (or another number), that is your category ID. In this case, the category ID is 5.

Step 5

Now that we have the category ID, we need to plug that into our snippet we inserted earlier. Since we are wanting to hide it from the homepage, we need to add a minus sign in front of the ID number like so:

<?php query_posts($query_string . '&cat=-5'); ?>

Make sure the number is inside the end single quote mark. That’s it, everything should work properly and your category should no longer display on your index.php page. If you have errors or issues, be sure to look over your code carefully to ensure it is correct.

Hiding Multiple Categories

If you want to hide more than one category, just add a coma after each category ID like so:

<?php query_posts($query_string . '&cat=-5, -45, -9'); ?>

If you have any questions please comment them below and I will help you as best I can.

About the Author

Enfuzed is a web and graphic design blog. Be sure to follow our social media accounts and subscribe to our RSS feed.

@EnfuzedWeb Google+

Leave a Reply