How to Exclude a Category From the Sidebar List in WordPress

Excluded (by felinebird)

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:

  1. 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.

  2. In Design > Widgets I removed the Category Widget and added a Text one.
  3. 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='); ?>
  4. If you want to exclude multiple categories, put a comma between each ID number.
  5. 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

It's Time!

Start your development project now!

Contact Me! >>


Keep Reading:
Converting a Static Website to WordPress: Mary Shelley and Frankenstein Part 2
How to Increase the Writing Space in WordPress
Using WordPress for a Custom Facebook Page - Step 1: Make a WordPress Page Template
How to Add a WordPress Default Post Thumbnail Image Without a Plugin


    • Flag says

      The best way to do id:


      Apperance> Widgets

      drag one one widget to the ‘Sidebar Widget’ .
      you can chose custom menu as well.

      If you dont drag something and leave the sidebar widget empty , by default all of them will show up.

      Hope it helps


  1. says

    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.

  2. says

    @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 :-)

  3. says

    @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.

  4. says

    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 Comparison

  5. says

    @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.

  6. says

    @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.

  7. holybagel says

    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!

  8. Jason Jonas says

    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!!

  9. says

    @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.

  10. Michelle says

    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!

  11. says

    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 . . .


  12. says

    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.

    • Dorival says

      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

          • says

            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.

  13. says

    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 =-.

    • says

      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.


      • says

        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 =-.

        • says

          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.


  14. says

    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.

    • says

      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=’);

      • says

        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!

  15. says

    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.



  16. says

    Thank you, thank you, thank you :)

    This worked like a charm. And after reading all the comments it worked in less than 5 minutes. This will save me more headache than you can know.

    I do have one question. :)

    My widgets have some style to them. If you go to the blog ( you will see the Topics list on the sidebar. Notice it is just a straight list. If you click on the archives tab you will see a very similar list but it is bulleted and there is a smidgen of space between each item. Do you know of anything I can add to the php line that will pull in the style for the sidebar lists?

    I will also do some searching and if I find the answer I will come back and post it. But you have been so awesome with your help so far I thought maybe you would know the answer to this question too :)

    Thank you again. This is a wonderful bit of information.

    .-= Cindy´s last blog ..Test Post =-.

  17. says

    Hi Cindy – It looks like your sidebar list is using an ID called #feature in the style sheet. This could be added to the code for Topics.
    <div id=feature>

    This is from a quick look so you may need to adjust it – but it’s definitely a styling issue.

  18. says

    I had a question that I was hoping that you can help me, If my categories are structured like:
    – Laptops
    – Desktops
    – Software
    – Cameras
    – Audio/Video

    ex. If a somebody is viewing posts in the Computers category I would like the categories widget in the side bar to only display Laptops, Desktops & Software..

    Is there a way to get this done? Are you familiar how to change the code or use a plugin that maybe do that?
    Cheers! :)

  19. says


    I like this question, oh, believe me, I do.

    I see what you mean, and I too have been struggling for a solution. And I am actually getting it, but that’s probably not the way you are thinking of ?

    For each of the Parent folders you are speaking of, I create a separate folder with a separate WordPress installation, and I may also add a sub-domain.

    Then I just list all those sub site links in a Text widget of the main site.

    See from here: let’s call a site “Laptop Accessories”, and a few of the categories listed here might be “Backpacks”, “Skins”, “Keyboard replacements” etc. When a visitor clicks a link “Backpack”, they arrive to the Backpack site, where there are only backpack types listed.

    There might be a few challenges involved as how to quickly build new wordpress sites, preferably using the same settings as a “seed” site.

    Hope this serves at least as a kick-off for a better idea?

  20. Brian says

    Hi Kim,

    Thanks for the code but unfortunately it doesn’t seem to work. I know this was written a while ago before WP3.0 was released, but do you have any suggestions on how to fix it?

    When I tried the current code, the Categories heading was there, of course, but nothing was listed underneath so it’s not getting the categories list at all.

    Anyway, I do appreciate the article, really wish that WP would just add something to the Categories section (or Widgets) that allows you to exclude it from the sidebar.

    • Brian says

      Embarassing, but I realized that it should still be supported with the current WP version. I will keep playing around with it and see if it works, but if you have any tips, I would appreciate it.

      • says

        Hi Brian – I was going to say that I’m using the current version of WordPress and it still works. Is it just blank or are you getting an error message? You can try retyping the single quotes – if you copied the code block directly from the post that might be causing the problem.

  21. Brian says

    Hi Kim,

    I retyped the single quotes as suggested but still the same. Under the heading it’s just blank, no errors.

    • says

      PHP code won’t run in widgets by default. You may need to install a plugin like Exec-PHP in order for this to work.

      And, of course, make sure there is a post in the category that you are using – when a category is blank, it won’t be displayed.

      • Brian says

        Well, your code works but the “Executable PHP widget” plugin I have isn’t playing well with my page as the categories I want excluded are but inside that box are a bunch of blue circles.

        I will try and find another plugin but thanks for your quick replies, really appreciate it.

  22. says

    nice simplistic and logical approach – for various reasons, i took a slightly different route. I displayed only the child categories of my main ‘blog’ category. Any categories that need to be created for a blog post will simply be created with ‘blog’ as it’s parent category.

    here’s my little snippet: <?php wp_list_categories('child_of=5&title_li=Categories'); ?>

    • amanda says

      I like both the exclude and include, but when I do Kim’s main idea, the listing are nice, but the main category is formatted different than the subs, I can handle the main category being listed, but I would like them all formatted the same… anyway I can do this easily within this widget space? I assume it has to do with a nested list?

      When I do Brads idea (to list only the children)
      I get a ugly not so formatted “Category” from the title function

      I can change the name, but how can I reformat it inline?

  23. says

    Hi Kim,

    Nice post and first time I am on your site. But I am still not able to do this. I exactly did what you said. I just started my site/blog and I used arthemia theme. This theme requires to create two categories called “headline and featured”. I want to hide these two under the “categories” on my sidebar but your tip did not work..not sure if i am making a mistake!!


  24. says

    Hi Kim,

    I am trying to use Advanced Category Excluder but i am uinable to see the results in the website.
    I want to accomplish 2 things:
    I want to remove few Categories from the Home Page.
    I want to remove some other Categories in Sidebar which i have added as a Widget in the Sidebar. Sidebar wasn’t there in the theme which i was using. So i have added manually as a Widget.

    Is this ACE Compatible upto WordPress 2.7.1 Version only? My WordPress Version is 3.1.1
    I don’t want to edit the Widgets.php file as WordPress Verion is updated often.

    Can you please help me in achieving this 2 things?

  25. says

    Hallo Kim, first sorry OOT, im beginner in wordpress and php coding, the simple question is, what code to show Category list Without using widget/plugin? i look forward for answer :D please email me.

    Best Regards


  26. linuxaina says

    Thank you very much for this great article. It worked wonders! Although I beg you one thing: please find a moment to edit the post in order to add the essential requirement of the installation of the Exec-PHP plugin. It took me quite a while until I found it in the comments section.

  27. Helen says

    Hi Kim,

    This is a great and helpful article. Thank you so much :)
    I have a question:
    Can you think of a similar solution for excluding the same categories and posts in that category from Archives list as well? Also from Recent Posts list.

    One more question:
    When using your method, the “Number of posts” in each category doesn’t show. Is it possible to add a piece of code for that too?

    You are a so smart :) thanks

  28. says

    You post is almost what I am looking for. I only want to include a few categories in my list. Can I use the same code and just put include instead of exclude?

    My bright idea is to use the WYSIWYG widget to put an image on the left and my 4 categories on the right but I am not having much luck

  29. says

    It’s not going to work because I can’t display php without a plugin and then I have to use their widget which means I can’t do what I want :(

Comments are closed. Please contact me for specific questions or subscribe to my newsletter.