Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

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.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Search and archives
  • Tested with WordPress 7.1

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
<?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

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.