Hide a category from the blog page
Posts in the category you choose don’t show on the main blog page. They’re still on their category page and in search.
Before you switch it on: Replace 123 with the category’s ID (hover over it in Posts > Categories).
It arrives switched off, even when you install its whole pack with "Switch on after installing".
<?php
add_action(
'pre_get_posts',
static function ( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_home() ) {
$query->set( 'category__not_in', array( 123 ) ); // The category's ID.
}
}
);
Good to know
Block themes with a Query Loop block that doesn’t “inherit query from template” aren’t affected.
In these packs
- Search and archives: Better site search and cleaner archive pages.