How to Exclude a Category From the Sidebar List in WordPress
My portfolio page is created using posts and is not a static page like the About page. I did this to easily add and remove entries and so that the page didn’t become too large. It will display a set number of entries like any other blog post page.
The portfolio entries are in the category, portfolio. The code on the portfolio is set to only display that category.
I also use the Ultimate Category Excluder plugin so that the category does not display in my archives or in my rss feed. I’m hoping to spend some time on code based solution for that as well.
I realized that the Portfolio category was still showing up in the list of categories in the sidebar. I was using the Category Widget, because it’s easy, even though I’m not a big fan of widgets. The only way I could determine to exclude the category from the widget was by editing wp-includes/widget.php. For a brief moment that seemed like a really good idea. But every time I upgrade WordPress I would overwrite that file or I would have to save and redo my edits. So, not such a great idea after all.
Instead I used the list categories function and excluded the category that I didn’t want displayed. Here’s what I did:
- In Manage > Categories I hovered over the name of the category and got the id number that I wanted to exclude in the browser status bar. In this instance the number is 276.
http://www.kimwoodbridge.com/wp-admin/categories.php?action=edit&cat_ID=276
- In Design > Widgets I removed the Category Widget and added a Text one.
- In the new text widget, I gave it the title Categories and added the following code:
<?php wp_list_categories('orderby=name&exclude=276&title_li='); ?> - If you want to exclude multiple categories, put a comma between each ID number.
- If you don’t have a widgetized sidebar, you can add the code to your sidebar where your current archive code is located.
That’s all there is to it. I don’t know why it took me so long to notice it was in the list. I also don’t know why I was being a dunce about the solution; it’s very similar to excluding a page from the navigation bar.
Useful? Do you have a need for this? Do you think you will use it?
photo credit: felinebird
Related Posts:









November 28, 2008 at 9:22 am
Hey Kim, thanks for this tip. I always wondered and wished I could eliminate certain categories on different pages, felt like so much repetition. I knew there must be a way. Glad you did the work for me!
Toodles,
Dee
Dee Langdon – BloggerNewbie´s last blog post – The Elusive Comment
November 28, 2008 at 3:19 pm
Hi Kim – I wish I’d known about this before I changed my blog theme. I wanted to have more categories, but they wouldn’t all fit in the category section above my header. I would definitely try your suggestion when I have more time, as it will take me forever to re-categorise over 500 posts.
November 28, 2008 at 4:19 pm
can’t think of a place in my blog where this can be useful, but your detailed step-by-step procedure will surely be useful some day!
Raju´s last blog post – Send Free SMS to India, UK and Other Countries
November 28, 2008 at 4:25 pm
Kim
Is there a way to arrange the categories in the order you choose rather than abc?
Dee Langdon – BloggerNewbie´s last blog post – 8 Writing Tips
November 28, 2008 at 4:32 pm
@Dee – Great! I’m always happy when I write about something someone actually wants to know :-)
There are three parameters for orderby
name – alphabetical
ID – the categories ID number
count – the number of posts in that category
Not sure if any of those will do what you need but there the only ones that can be used.
@Cath – Bummer. Categories can be bulk edited via the database but that takes some knowledge of mysql. I had a site where I converted all the categories to tags not knowing that would wipe out all of the categories. It was about 3000 posts at the time – wasn’t pretty.
@Raju – File it away :-)
November 28, 2008 at 7:03 pm
Thanks Kim. Useful, as always.
November 28, 2008 at 8:15 pm
Grrr. This is something that I really needed to know about 3 months ago. I hate it when things like this happen.
Great information though.
Wesley´s last blog post – It rained today.
November 28, 2008 at 10:14 pm
@Vered – Thank you :-)
@Wesley – Sorry :( I didn’t know you 3 months ago.
November 29, 2008 at 7:20 am
I just got to know that your blog is listed on wordpress.alltop.com. Awesome Kim!!
Raju´s last blog post – Send Free SMS to India, UK and Other Countries
November 29, 2008 at 7:40 am
@Raju – Thank you. It’s only been listed for about 5 days.
November 29, 2008 at 10:51 am
to me this is not useful since i don’t have many categories… as for the ordering the only thing i can think of is a small code snippet that would allow you to list which categories you want to show…
stratosg´s last blog post – Delete post revisions without any plugin
November 29, 2008 at 2:56 pm
@Stratos – Normally I wouldn’t need this either but I didn’t want my portfolio category listed on the front page. Some people’s themes list categories as navigation in the header – in that instance excluding categories could be really useful.
November 29, 2008 at 11:32 pm
These tips really help especially somebody like me who go into the code and hack to hide or display stuff. I did it with the page hiding until I read your tip the other day.
One of the other issues (in fact a limitation with WP, at least till 2.5.2) I have is the ordering of the pages. Is it already improved in WP latest versions. I have about 9 pages (off which some are hidden) and everytime I want to sequence it, I have to edit all of them to change a priority number.
Another pain with sequencing is that of the categories which WP defaults to alphabettic order.
I guess, they are least bothered about this aspect, release after release :lol:
Ajith Edassery´s last blog post – Free blogging platforms – Blogger v/s Wordpress.com Comparison
May 31, 2009 at 10:25 am
I remembered your post and implemented this category exclusion logic after referring this post again :) Right now, I am hiding as many as 5 categories from the sidebar widget to make room for the AdSense block that follows
June 1, 2009 at 6:18 am
Hi Ajith – Great! I’m so glad the article was helpful.
November 30, 2008 at 12:08 am
Now don’t go calling yourself a Dunce, at least you were able to work it out. A lot of people would have given up. Good on you for persevering and getting the job done.
Sire´s last blog post – ProBlogger Plea To Amazon Associates Program
November 30, 2008 at 8:22 am
@Ajith – I’m glad the tip helped you out. The ordering of pages and categories is very limiting. Oh – and I know what you mean about the sequencing of pages – that little box where you put 0,1,2 etc. I worked on one theme where that wouldn’t work – it was very annoying,
@Sire – I don’t really think I’m a dunce ;-) I’m just a big fan of self-deprecation.
December 2, 2008 at 12:27 pm
Nice tip Kim. Do you know any plugins for managing the categories on a blog. I am thinking of deleting and modifying some categories on my blog.
Madhur Kapoor´s last blog post – Manage Bookmarks Visually with Tidy Favorites
December 2, 2008 at 1:30 pm
@Madhur – Thanks! I don’t know of a plugin for that – that topic seems to be coming up a lot lately too.
Can you go to Manage > Categories click on the name of the category and then rename it? I did that with some of mine recently. If you don’t have too many categories it shouldn’t take too long. You can also bulk delete from
Manage > Categories too.
January 15, 2009 at 3:48 pm
Thanks Kim!
I was have problems with Categories not showing up correctly in arthemia theme and this solved on how to display the 5 categories in the browse categories and i the order I choose
thanks again!
January 15, 2009 at 9:28 pm
@holybagel – Thank you for visiting and commenting. I’m glad the code worked for you :-)
January 19, 2009 at 3:29 pm
Thank you so much for this,
I was searching for hours only to find useless and waaaaaay to complicated instructions, figures it would be this easy so I’m glad I found this. Keep up the good work!!
January 19, 2009 at 4:51 pm
@Jason – Thank you for visiting and commenting.
Sorry you spent so much time searching – I’ve done the same thing. When I suddenly get that aha moment and have a mental breakthrough I write it up and share it with others.
January 28, 2009 at 6:17 am
Thank you very much for this! I’m having to use wordpress for a client in a way I haven’t done before, which means a lot of hard coding in order to be able to edit specific styled regions of the homepage, I’m using posts so that the client can change the text without touching the code. Because those posts aren’t part of the blog I needed to exclude them from the sidebars.
Your tutorial was a big help!
January 28, 2009 at 1:26 pm
@Michelle – Thank you for visiting and commenting. I’m really glad that this article is helping you exclude the content :-)
April 7, 2009 at 10:34 am
I’ve just upgraded to 2.7.1, and it broke my hide-categories plugin. I couldn’t get your tip to work. The php included in a text widget would not execute. I found this Sidebar PHP Code Widget Plugin that did the trick. http://wordpress.org/extend/plugins/php-code-widget/
Robert Reed´s last blog post – Vero Beach
April 8, 2009 at 8:06 am
Hi Robert – You need a plugin like exec-php to run php code in posts, pages and text widgets. I should have mentioned it in the article – I often forget to mention it because I use that plugin on all my sites.
http://wordpress.org/extend/plugins/exec-php/
I’m glad you found a plugin that worked for you.
May 11, 2009 at 9:55 pm
Thanks for the tip! The php code widget did the trick to make this work.
Mark Powell´s last blog post – Geo & Real Estate Domain Sales Report – April 2009
May 12, 2009 at 6:47 am
Hi Mark – Great! I’m glad it worked out for you.
July 6, 2009 at 12:06 am
Thank you very much! I added the code: hierarchical=0& before your code so my list would be flat and not show the hierarchy. Full code is:
Now that’s I’ve done that, it looks like I have to manually exclude all my child categories along with the parent.
So, I was wondering, is there a way to exclude all child categories from a certain parent? For example, now I can exclude category 16 (parent) but category 17 (child) still shows up. I don’t want to manually update the code everytime a child category is added . . .
Thanks!
July 6, 2009 at 9:10 am
Hi Jill – I don’t know an easy way to do that without having to edit the code
manually each time. Any plugin solutions are going to exclude a category from the entire page not just in one section.
July 6, 2009 at 10:42 am
Okay, thanks for your reply. And, thanks again for your post!
September 17, 2009 at 4:34 pm
Hi,
Im from Brasil an i need some help.
I need exclude a category post (Destaque) from my list of posts. See exemples: http://www.luciaconde.com.
Last post is repeated
PS: Sorry…my english is not so good.
September 17, 2009 at 4:42 pm
Oh…sorry, i forgot the code:
<div class="post" id="post-">
<a href="" rel="bookmark" title="Link permanente para ">
Postado por | Categoria: | Postado em
<a href="">Continue lendo
September 18, 2009 at 7:02 am
Hi Dorival – Do you need to exclude an entire category or just one post?
September 18, 2009 at 9:03 am
Hi Kim. Just “Destaque” category
September 18, 2009 at 9:36 am
Hi – It looks like you are using the Categories widget under
Appearance >Widgets. You can’t exclude a category with the widget. You would want to remove it and then add a text widget with code like the following in it.
< ?php wp_list_categories('orderby=name&exclude=276,1179&title_li='); ?>
Of course, you would also need to install a plugin like Exec-Php in order to use php code in a text widget.
January 7, 2010 at 11:48 pm
Thanks for the tip Kim. That was a smart idea. Side stepping the upgrade process is a great suggestion. I try to avoid code WordPress hacks whenever possible. The text widget didn’t work for me, so I used the PHP Code Widget plugin to put in the php code you suggested and then excluded the categories from there. I also use the Widget Logic plugin to exclude the categories list from specific pages. It works like a charm. Thanks again for sharing.
Charles @ Simple Daily Recipes´s last blog ..Interview with Jeff Hertzberg and Zoe Francois
January 8, 2010 at 9:02 am
Hi Charles – I’m glad it’s working. I’m going to take a look at the plugins that you mentioned. While I try to avoid plugins as much as possible, I do use them more frequently on sites I develop.
Thanks!
January 8, 2010 at 1:10 pm
Oh Kim! Plugins are your friend :)
It is absolutely amazing how many great plugins are out there. To me WordPress truly delivers on the promise of open source and reusable blocks of code. It is the super hero of website development and plugins are the cool hooks and levers that hang off the utility belt to make the online adventure exciting.
Charles @ Open Source Marketer´s last blog ..Video: What Does Your Facebook Status Say About You
January 8, 2010 at 4:12 pm
Hi Charles – I agree. But with each plugin there is another chance of their being plugin conflicts or issues with the plugins when WordPress is upgraded. In most instances, I prefer to use a code solution.
Thanks!
January 18, 2010 at 7:33 am
Hi Kim,
Thanks very much for the solution, and the further advice on exec-PHP. Worked a treat, I was trying to remember how I did it on a site I built almost two years ago so having this post as a reference to promopt my memory was great. Thank you.
However, just one thing, obviously, in the default “Categories” widget, you have the ability to show ‘post count’ next to each link. Any ideas on how I do that with your code in my new text widget?
Also, is there any way we could contribute a working widget for category exclusion to the wordpress community? I’m sure lots of people would find this useful. I’d be happy to help if anyone else thinks it’s a good idea!
Many thanks for your efforts and time.
Jonathan
January 18, 2010 at 8:08 am
Hi Jonathan – I thought there was a plugin or widget to do this but while looking this morning didn’t locate anything. Something like page mash but for categories would be useful. If you know how to make a plugin, you can and add it to the directory.
list categories has a parameter called show count, which by default is turned off. You could add &show_count=1
php wp_list_categories(‘orderby=name&show_count=1&exclude=276&title_li=’);
January 18, 2010 at 8:33 am
Kim, I cannot thank you enough for your super quick response. Worked a treat and I’m all done with my design now, thank you! :)
I have never built a plugin before, but would like to give it a go. I’ll let you know how I get on should I ever get the time to do it! :)
Thanks again and all the best!
January 18, 2010 at 8:40 am
Hi Jonathan – Great! And you just happened to leave a comment during my morning check of comments to answer :-)
January 26, 2010 at 12:22 pm
Thanks! Looked at two articles on the wordpress site and didn’t find much on this topic. Took 5 seconds to do this after reading your post.
Best,
Kris
January 26, 2010 at 2:33 pm
Hi Kris – Great! I’m glad it helped.
March 16, 2010 at 5:54 pm
Just wanted to say thank you.. Your post saved my life/time with a client!
James´s last blog ..Commented on “TechBurgh”
March 16, 2010 at 9:44 pm
Hi James – Great! I found a post yesterday about the Thesis theme that did the same thing for me.