There will be times when you need to not show a category on a certain page. You can either code this manually or use a plugin. Here are some options:
Manually Excluding a Category
Step 1: Go to your WordPress Dashboard
Step 2: Expand the Posts dropdown from the left sidebar
Step 3: Click on the Categories link
Step 4: Click the Category you want to exclude
Step 4: In you browser address bar you will see a url that contains your Category ID. It looks something like this:
<br/>http://www.yourwebsite.com/wp-admin/categories.php?action=edit&cat_ID=5<br/>
The Category ID is 5 at the end of the url (cat_ID=5).
Step 5: Open the Functions.php file for your Theme
Step 6: Past the following code before the closing PHP tage ?> and make sure you change -xx in the code below to your category id
function exclude_category($query) {
if ( $query->is_home ) {
$query->set('cat', '-xx');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
Try it out. I will be updating this post with other examples of excluding categories and plugins you can use.
{ 0 comments }
