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
- Download, install and activate the Sidebar PHP Code Widget Plugin
- 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
- Navigate to Appearance > Widgets
- Drag PHP Code from Available Widgets to your Current Widgets
- Edit the PHP Code Widget and add the following code (replace 1,2,3 with the category IDs you would like to exclude):
<?php wp_list_categories(‘orderby=name&exclude=1,2,3&title_li=’); ?>
- Click Done and then click Save Changes to save the changes to your Sidebar
- 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.