Skip to content

Instantly share code, notes, and snippets.

@NichlasB
Last active June 22, 2017 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NichlasB/e50134cc6235dc1b91c4aa6537f0e841 to your computer and use it in GitHub Desktop.
Save NichlasB/e50134cc6235dc1b91c4aa6537f0e841 to your computer and use it in GitHub Desktop.
Exclude Categories from WordPress Blog Page
<?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' );
@NichlasB
Copy link
Author

NichlasB commented Jun 22, 2017

Display ONLY defined categories on blog page: https://gist.github.com/NichlasB/47f6aa506477724d0beb042af6798659

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment