mizner
10/19/2016 - 4:50 PM

Simple Remove Category from WordPress Blog Page

Simple Remove Category from WordPress Blog Page

<?php
/**
 * Plugin Name: Remove Category
 * Plugin URI: http://mizner.io
 * Description:
 * Version: 1.0
 * Author: Michael Mizner
 * Author URI: http://mizner.io
 * License:
 */

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );
function foo_modify_query_exclude_category( $query ) {
	$category_id = '138';
	if ( is_home() ) {
		if ( $query->is_main_query() && ! $query->get( 'cat' ) ) {
			$query->set( 'cat', '-' . $category_id );
		}
	}
}