How to exclude categories from the homepage?
-
I have two categories on my site that are necessary to keep, but should not be displayed on the site’s homepage. How do I modify either the child theme’s functions.php or template-knowledgebase.php to exclude those two categories?
I have already tried several plugins supposed to exclude categories from the homepage (such as Advanced Category Excluder, Ultimate Category Excluder, and WP Exclude From Homepage) and they do not work.
I have also tried code snippets in functions.php, such as the one below, that several sites recommend to exclude categories from the homepage. This code also does not work.
function exclude_category_home( $query ) { if ( $query->is_front ) { $query->set( 'cat', '-1, -58' ); } return $query;} add_filter( 'pre_get_posts', 'exclude_category_home' );
Any suggestions would be appreciated.
Thanks!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to exclude categories from the homepage?’ is closed to new replies.