Ubermenu is awesome. It’s incredibly versatile and makes the most beautiful wordpress menus out there.

In this quickie we’re looking at a specific use case in which ubermenu needs a little tweak.


The Problem:

We want to use submenu items to link to different sections in a page (by id), which works great. The issue arises when your on the page itself. Because the submenu items aren’t loading a new page but scrolling to a section the submenu remains open when you click it.

ubermenu submenu visible


The Solution:

This simple bit of code removes the ‘ubermenu-active’ class from the parent item when the submenu item is clicked.

jQuery(function($) {
$(".ubermenu-submenu li").click(function(){
$(this).parent().parent().removeClass("ubermenu-active");
});
});

ubermenu submenu visible

Depending on your wordpress theme you may have a place to paste custom code. Otherwise you can put it in script tags in your header template.