Don’t poison your blogroll with the superfluous categories

When you start building your WordPress website, you’ll probably need several categories which will contain different posts. Usually, WordPress will show all those posts in your blogroll which can be found on the homepage. That means that every time you publish a post, no matter in which category it is sorted, the post will be displayed on your homepage.

But there will be times when you wouldn’t need posts from specific categories to be shown there.

Remove categories from blogroll:

Just as an example, you might have installed a plugin which will automatically publish YouTube videos in a new category you had created. Maybe you have used it to automatically publish movie trailers, but you don’t want to overpopulate your homepage with that category. You can find a different place to show those trailer (sidebar for example) and you will want to remove the trailers category from showing on the homepage.

This is just one example why not to show a category in the blogroll. You might have a completely different reason but we’ll show you an easy way to do that:

  1. Open functions.php
  2. Copy and paste the following code:
  3. function wploop_exclude_category( $query ) {
    if ( $query->is_home ) {
    $query->set( 'cat', '-10' );
    }
    return $query;
    }
    add_filter( 'pre_get_posts', 'wploop_exclude_category' );
  4. Find category ID
  5. You can do that quickly by navigating to Posts -> Categories, choosing the one you want to exclude from the homepage. Edit the category and find its ID in the address bar. The ID will look like this: category&tag_ID=45

  6. Replace that ID on the third line but leave the minus symbol next to it
  7. Save changes

That’s all it takes to remove a category from showing in your blogroll. You won’t be needing any plugins (although such plugins do exist).

If you want to exclude multiple categories from showing up on your homepage, simply add additional IDs separated by comma:

$query->set( 'cat', '-10, -11, -12' );

Now that you have excluded one or more categories from showing in the blogroll, you might be interested in showing posts from that category in a separate list.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *