I’m trying to work out how to hide a particular category (id=89) from my wordpress blog archive page. I want to be able to use specific blog posts with this category on another part of the site but i don’t want them to appear in any of the main archive pages (as a category link or show the posts themselves via the archive page). I have the following code on my page but i don’t know where and what to add to it to hide this id:
<h3>Categories</h3>
<?php
$categories = get_categories( array(
'hide_empty' => 1,
) );
foreach( $categories as $category ) {
// print_r($category);
$category_link = get_category_link( $category->term_id );
?>
<ul>
<li><a href="<?php echo $category_link; ?>"><?php echo $category->name; ?></a></li>
<?php
}
?>
</ul>
</div>
```
2
Answers
For the category list, modify your code like this:
To also exclude posts from this category in your archive pages, add this code to your theme’s functions.php file
If you need to exclude multiple categories, you can modify the arrays like this:
$query->set('cat', '-89,-90,-91') // For the archive pages
You can simply exclude the category in your
get_categories
args: