WordPress Hide Categories Sidebar Plugin

In the following simple solution, I will show you how to exclude or hide categories from your WordPress Sidebar by using the PHP Code Widget Plugin. In the past, I explained how to accomplish this by hard coding the changes into the WordPress wp-includes/widgets.php file. However, past methods may cause you to lose those exclusions when upgrading, if the widgets.php file has changed.

The following process utilizes the "Sidebar PHP Code Widget Plugin" to enable us to use PHP code in the sidebar. This is necessary because PHP code cannot be executed from a standard sidebar text widget.

Easily Hiding Categories from WordPress Sidebar

  1. Download, install and activate the Sidebar PHP Code Widget Plugin
  2. Navigate to Posts > Categories and hover over the name of the category you would like to exclude and get the Cat_ ID number from the browser status bar
  3. Navigate to Appearance > Widgets
  4. Drag PHP Code from Available Widgets to your Current Widgets
  5. Edit the PHP Code Widget and add the following code (replace 1,2,3 with the category IDs you would like to exclude):

    <ul>
    <?php wp_list_categories('orderby=name&exclude=1,2,3&title_li='); ?>
    </ul>

  6. Click Done and then click Save Changes to save the changes to your Sidebar
  7. Go view your site!

Note: The code is wrapped with <ul> tags to allow the markup to validate. Your template may or may not require this.