How to hide the sub menu after a menu item link is clicked

Close desktop menu after click

If you are using a one page theme or have anchor links within your sub menus, and want to close the desktop menu as soon as one of the links is clicked:

  1. Install the WPCode plugin (or any plugin that lets you add custom JavaScript to your site)
  2. Go to Code Snippets > + Add Snippet, create a new snippet with the Code Type set to “JavaScript Snippet” and enter the following:

Close mobile menu after click

If you are using a one page theme and want to close the mobile menu as soon as one of the links is clicked:

  1. Install the WPCode plugin (or any plugin that lets you add custom JavaScript to your site)
  2. Go to Code Snippets > + Add Snippet, create a new snippet with the Code Type set to “JavaScript Snippet” and enter the following: