For the vast majority of websites using
WordPress Installation, the homepage displays all recently updated posts. For certain reasons, we may not want posts from all categories. You can achieve this through the following two methods:
Exclude Specific Categories from Homepage。
Plugin to Exclude Specific Categories from Homepage
Ultimate Category Excluder is a
WordPress Pluginthat excludes post categories based on settings. It not only supports excluding posts from specific categories from the homepage but can also be set to exclude specific categories from TAGs, search results, archive pages, and RSS. It is very practical and suitable for novice users.

Ultimate Category Excluder is a free WP Plugin. You can download and install it from the link below, or directly search and install it from the Admin Dashboard.
Download LinkExclude Categories Using Code
If you don't want to install a plugin just to exclude category posts, you can also use code to achieve this. The specific method is to copy the following code into your
Theme's functions file.
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-5' );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_category_home' );In the above code, the second line determines the page: is_home is the homepage, is_search is the search results page. If you want other pages, you can also modify the code. The '-5' in the third line represents blocking all posts from the category with ID 5. You can extract the category ID by hovering your mouse over the category link in the URL. To exclude multiple categories, separate them with commas, e.g., '-5, -1'.
If the homepage is a static page, how to exclude category posts on the blog archive page?Naibabiji currently uses a static page as the homepage, with blog posts called on another page. In this case, using the above code would cause both the homepage and the blog page not to display content from the excluded category. To exclude only from the homepage and not from the blog archive page, edit your website's Theme file (mine is index.php) and insert the following code.
The above code may need to be adapted. The query part is
query_posts($query_string .'&cat=-1');
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.