Recently, I did some pro bono work and set up a quick and simple WordPress website for a Fiverr freelancer who really needed it.


Since he’s a content writer, he wants to add some sample writings as a portfolio.

Since those consist of various articles, it’s best to use the posting/blog system, not a page. So, I created a category called “Samples”.


But, as you might already know, what you add in a category also shows on the main WordPress blog page, which in cases like this one is not ideal.

So, in this tutorial, I’ll show you how to exclude category posts from your WordPress blog page using a code or a plugin!

This will also work if your homepage displays your latest posts, making it your blog page, basically.


Exclude a category from your WordPress blog page using code

Here’s what you need to do.

Step 1

You’ll need to find the ID of the category that you want to exclude from your WordPress blog page.

Step 2


Access your WordPress website’s files and find the functions.php file. That’s where you’ll add the code.

edit WordPress functions.php cpanel

Editing functions.php via cPanel

It should normally be found in:


If you want to edit the file on add-on domain, not your main one, then it should normally be in:


I recommend backing up the file or the whole website, and also having a child theme in place, otherwise, your changes will be lost with the next theme update.

Step 3

Add the following PHP code right at the very bottom of the functions.php file, or right before the ?> closing tag (if there’s any).

function exclude_category_posts( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-7' );
add_action( 'pre_get_posts', 'exclude_category_posts' );

exclude category blog page wordpress

Note that you have to replace the category ID ('-7' in my example) with your own.

If you want to exclude multiple categories from your blog page in WordPress, then add more IDs in $query->set. For example:

function exclude_category_posts( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-7, -12, -15' );
add_action( 'pre_get_posts', 'exclude_category_posts' );

Again, don’t forget to replace the category IDs with your own!

Exclude a category from your WordPress blog page using a plugin

Even though this is the easiest method, I strongly recommend going with the first one because the fewer plugins you have, the better!

Step 1

Install the Ultimate Category Excluder plugin.

Here’s how to install a WordPress plugin.

Step 2

Go to the plugin’s options in Settings -> Category Excluder.

ultimate category excluder wordpress plugin

As you can see, it lets you exclude categories from different places in WordPress:

  • Front page;
  • Feeds;
  • All archives;
  • Search.

All you have to do is to check one or multiple boxes, click the Update button, and the WordPress categories will be removed from the selected places.

That’s a wrap

I hope you found the post useful and comprehensive, and you managed to successfully exclude a category from your blog page in WordPress!

Don’t forget to share the post to help out others!

You can quickly subscribe to my newsletter by using this link.

If you have any questions or thoughts, drop a comment or send a message via contact or Facebook page.

You can also hit the follow button on Twitter and subscribe to the YouTube channel.

My WordPress website or blog installation service is at your disposal!

On-going WordPress support and maintenance services are on the menu as well!