Skip to content

Instantly share code, notes, and snippets.

@zlove
Last active November 17, 2015 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zlove/7c7b3579f319cc37c62c to your computer and use it in GitHub Desktop.
Save zlove/7c7b3579f319cc37c62c to your computer and use it in GitHub Desktop.
jQuery to allow Wordpress menu items to open sub-menus directly using mmenu
/*
mmenu (http://mmenu.frebsite.nl/) has a way to make a click on a menu item
open a sub-menu (as opposed to a click on the arrow to the right of the item).
See:
http://mmenu.frebsite.nl/support/tips-and-tricks.html#tt-subopenlinks
https://github.com/BeSite/jQuery.mmenu/issues/45
However, Wordpress menus by default do not allow an easy way
to use either of these techniques. This snippet modifies
the menu HTML generated by Wordpress / mmenu,
and adds appropriate classes to any menu item
with a link starting with '#' to have that item
open the sub-menu directly.
*/
var $the_menu = $('.wp-menu-selector-here');
$the_menu.mmenu();
$the_menu
.find("a:not(.mm-subopen)[href^='#']")
.prev(".mm-subopen")
.addClass("mm-fullsubopen ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment