Hiding certain categories in WordPress navigation

Last updated on November 28, 2011. Tags: , ,

The category list is one of the major components of a typical blog or any website powered by WordPress. Categories are used to classify blog posts into subjects. They can also be used in some other way such as classifying products (if you're using WordPress website as online store) and organizing photos into albums (if you have an online gallery). The category list provides a list of links to all categories with at least one entry.

In some cases, we would like to hide certain categories. Meaning, the category does really exist and can be accessed in http://domain.com/category/specific-category-name/ but the link towards it in the category list is absent.  Perhaps, you intend to use those categories only in managing the blog and is therefore not intended to be accessible to your audience. Perhaps you want to hide a category because it is used only to enable another WordPress tweak such as preventing some posts from appearing in the search results.

The category list is usually in the sidebar (sidebar.php) but may also be found in some other parts of the layout. The list is generated by the following PHP code:

<?php wp_list_categories(); ?>

Sometimes, the code has some other components within the parentheses.

<?php wp_list_categories('title_li='); ?>

To hide a category, determine which category you would like to exclude. Then, add exclude=10 in the code, where 10 is the category ID of the category you wish to hide, as shown in the code below.

<?php wp_list_categories('exclude=10'); ?>

Just replace 10 with the actual category ID of the category you wish to hide. If you do not know how to determine the category ID, visit this post.

You can hide several categories, just indicate the IDs of these categories separated by comma.

<?php wp_list_categories('exclude=10,11,15'); ?>

If there are other parameters in the parentheses, you can separate them by putting ampersand (&) between them.

<?php wp_list_categories('exclude=10,11,15&title_li='); ?>

An alternative method is to hide all but few selected categories. Simply replace exclude with include and indicate the category IDs of the ones that you want to show up in the list.

<?php wp_list_categories('include=9,12,17'); ?>

Note that if you hide a parent category, all subcategories under it are also not visible in the category list. Also, categories without any posts assigned to them are also not visible.

Posted by Greten on November 30, 2009 under WordPress

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati

Related Posts

You might also be interested (randomly generated):

Post Comments





Comment Rules and Reminders

  • The links to the commentator's e-mail do not have nofollow tag. However, I will be very strict in approving comments.
  • When you comment, please say something that indicates that you indeed read my post. If your comment is a general statement that can fit to any blog post about any topic, it will be regarded as spam.
  • What you write in the name field may include keywords to your website provided that (1) it's only up to four words long and (2) at least one of these four words is your first name or nickname. I rather reply to Bob or to Joe Smith than to Online Marketing Tips.
  • Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.
  • Fields marked with asterisks (*) are required. Your email will never be displayed in public.