This code will work in any theme and is tested using the Genesis Sample child theme by StudioPress. The code removes all categories from any nav menu if they don’t yet contain posts. This way you can setup a new menu under Appearance > Menus, add categories and only the categories containing posts will be displayed in the menu.
Another option is to use code to create a dynamic menu which automatically adds new categories to the menu as they are created but doesn’t display them in the menu unless they contain posts. The code for this is also included in this tutorial at the end of the post.
Here’s the code to exclude empty categories from any nav menu created on the under Appearance > Menus admin screen.
Based on a question from a member:
Looking for function to hide empty categories in Genesis Primary menus.
Here’s the code which enables you to dynamically add new categories when they are created.
Leave a Reply
You must be logged in to post a comment.