askdesign
11/19/2015 - 11:13 PM

Hide or Remove Categories from Home Page Blog

Brian Gardner and others

<?php
//* Brian Gardner
//* Do NOT include the opening php tag
//* Exclude categories from blog homepage
add_action( 'pre_get_posts', 'bg_exclude_categories' );
function bg_exclude_categories( $query ) {
	if( $query->is_main_query() && $query->is_home() ) {
		$query->set( 'cat', '-5,-7' );
	}
}
<?php
//* https://www.wpwhitesecurity.com/wordpress-tutorial/exclude-category-wordpress-blog/
//* Replace the xx (mentioned in line 3 of the above code) with the category ID you 
//* recorded in step 1 of this WordPress tutorial. Leave the minus ‘-‘ sign in front of the category ID, only replace the xx

function exclude_category($query) {
if ( $query->is_home() ) {
$query->set('cat', '-xx');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

//* exclude multiple categories:
//* $query->set(‘cat’, ‘-124 -125 -126’);
<?php
//* http://www.wpmayor.com/how-to-hide-or-remove-categories-from-a-wordpress-homepage/

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-5, -34' );
}
return $query;
}

add_filter( 'pre_get_posts', 'exclude_category_home' );
<?php
/** 
Sridhar Katakam
* https://sridharkatakam.com/how-to-exclude-posts-from-a-specific-category-on-the-posts-page-in-wordpress/ 
* exclude single category 
*/

add_filter( 'pre_get_posts', 'sk_exclude_category_posts' );
/**
 * Excludes posts from "Uncategoized" category on the Posts page.
 * @param object $query data.
 */
function sk_exclude_category_posts( $query ) {

    if ( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
        $query->set( 'cat', '-1' );
    }

}

/** exclude multiple categories */
add_filter( 'pre_get_posts', 'sk_exclude_category_posts' );
/**
 * Excludes posts from "Uncategoized" and "Featured" categories on the Posts page.
 * @param object $query data.
 */
function sk_exclude_category_posts( $query ) {

    if ( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
        $query->set( 'cat', '-1, -36' );
    }

}
<?php
add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
/**
 * Exclude Category from Blog
 * 
 * @author Bill Erickson
 * @link http://www.billerickson.net/customize-the-wordpress-query/
 * @param object $query data
 *
 */
function be_exclude_category_from_blog( $query ) {
	
	if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
		$query->set( 'cat', '-4' );
	}
}
<?php

add_action( 'pre_get_posts', 'exclude_category_posts' );

/**
* @author Brad Dalton - WP Sites
* @example http://wpsites.net/web-design/exclude-category-posts-page/
* final $query is slightly different from Bill's; it uses an array
*/

function exclude_category_posts( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'cat', array( -27, -30 ) );
    }
}