Last active
June 22, 2017 21:56
-
-
Save NichlasB/e50134cc6235dc1b91c4aa6537f0e841 to your computer and use it in GitHub Desktop.
Exclude Categories from WordPress Blog Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
/** | |
* exclude-blog-categories.php | |
*/ | |
function cf_exclude_chosen_categories( $query ) { | |
if ( $query->is_home() && $query->is_main_query() ) { | |
$query->set('cat', '-3 -4 -5 -6'); | |
} | |
} | |
add_action( 'pre_get_posts', 'cf_exclude_chosen_categories' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Display ONLY defined categories on blog page: https://gist.github.com/NichlasB/47f6aa506477724d0beb042af6798659