Remove Category From Blog Page (PHP)

Estimated reading: 3 minutes 12 views

When running a blog, it’s easy to let content accumulate under a variety of categories. But as your site grows, not every category deserves equal spotlight. Removing a category from your main blog page can actually enhance user experience, improve site structure, and make your content strategy more intentional.

Not all categories serve your primary audience. For example, if you occasionally post behind-the-scenes updates, technical changelogs, or personal notes, have two types of content ie recipes and articles, then you might not want these appearing alongside one or the other. Removing less-relevant categories from your blog page keeps the focus on the content that brings the most value to your readers.

Removing a category from your blog page doesn’t mean hiding it from the world—it means being strategic about what shows up where. It’s a simple but powerful way to keep your blog sharp, relevant, and focused on what matters most to your audience. Our Taster theme uses this approach because it has a dedicated Recipe Landing Page, so the blog page can be reserved for articles.

Code Snippet

Here’s the exact snippet we used on our Taster theme:

function exclude_category( $query ) { 
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '-23' ); // Replace 23 with your category ID
    }
}
add_action( 'pre_get_posts', 'exclude_category' );

Where to Add This Code

Here are two easy options:

Option 1: Install WPCode Lite Plugin

This is by far the safest method and is beginner friendly if you’re not used to editing theme files.

  1. Search for WPCode Lite plugin in your website dashboard.
  2. Install the plugin.
  3. Go to Snippets > Add New.
  4. Give your snippet a name like “Remove Category From Blog Page.”
  5. Paste the code above.
  6. Choose “Run snippet everywhere”.
  7. Choose PHP, not CSS or any other.
  8. Change the category ID number on the third line to match the category on your website—see details below.
  9. Save and activate.

✅ Done!

Option 2: Functions.php

We don’t advise this option unless you’re a developer or if you feel comfortable editing theme files:

  1. Open your functions.php file .
  2. Paste the snippet at the bottom.
  3. Save and upload if needed.

💡 Tip: Always use a child theme to avoid losing changes when your theme updates.

How To Find Category ID

If you want to exclude a category from your blog page or use it in custom queries, you’ll need the Category ID. While WordPress doesn’t display it directly, it’s easy to find in just a few steps:

✅ Step-by-Step Instructions

  1. In the left-hand menu, go to Posts → Categories.
  2. Find the category you want to get the ID for.
  3. Hover over the category name (or click Edit under the category name).
  4. Look at the URL in your browser’s address bar.
    It will look something like this 👉 https://yourwebsite.com/wp-admin/term.php?taxonomy=category&tag_ID=23&post_type=post
  5. The number after tag_ID= is your Category ID.
  6. 👉 In this example, the Category ID is 23.

NOTE: We use WPCode Lite because it’s more flexible than others, there’s no need to upgrade to pro unless you’re a developer, it offers many free snippets, can choose where to run it, won’t publish if the code is wrong so won’t break your site, PHP is included compared to others you have to buy the their pro, and best of all the free version can easily be downloaded from your WordPress Repository.

Leave a Reply

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

Share this Doc

Remove Category From Blog Page (PHP)

Or copy link

CONTENTS

Join The Party For Fun Updates freebies & Big Discounts!

JoiN Glamsy Cloud! Free STUNNING Kadence Templates Included!

Start with 5 gorgeous Kadence blocks on us. Love them? Unlock ‘50 FREE FOREVER‘ that’s 50 more free blocks just for choosing any essential tool from our trusted fav stack!

Grab Your Free Templates
Review Your Cart
0
Add Coupon Code
Subtotal

 

Subscribe

×
Cancel