Wordpress exclude certain category IDs from main or front page


/ Published in: PHP
Save to your folder(s)

Add to functions.php. Replace IDs (64, 104 below) with categories you want to exclude.


Copy this code and paste it in your HTML
  1. function BI_exclude_category( $query ) {
  2. if ( $query->is_home() && $query->is_main_query() ) {
  3. $query->set( 'cat', '-64,-104' );
  4. }
  5. }
  6. add_action( 'pre_get_posts', 'BI_exclude_category' );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.