Can anyone tell me how to stop the top level menu items in the WordPress Admin sidebar auto-expanding when that top level item is clicked, or a submenu item chosen from the fly-out menu?

For clarity, I'm not talking about the left/right expansion/collapse of the sidebar menu itself, but the up/down expansion to show submenu level items. e.g. The sidebar shows

Posts : Pages : Appearance : Tools : Settings : ... etc.

If I hover over "Appearance", the submenu items are presented as a fly-out, allowing me to click on one. However, when I do, or if I click on "Appearance" itself, that item auto-expands so that the sidebar now shows

Posts : Pages : Appearance - Themes - Widgets - Background : Tools : Settings : ... etc.

I want it to not expand on selection of a top level or sub menu item. I've searched Google and specialist sites like this one several times for an answer but can't find one. Plenty about expanding / collapsing the sidebar itself but only one about top level / submenu expansion. The proposed solution there (call to a javascript function) did not work for me.

Although it's trivial in the scheme of things, being unable to find the answer is starting to really frustrate me every time it does it!

Many thanks in anticipation.

  • Are you talking about modifying the WordPress admin, or something in your theme? Commented Jan 24, 2020 at 7:06
  • Sorry for not being clearer. The WordPress Admin sidebar.
    – Kevin4fm
    Commented Jan 24, 2020 at 7:07

1 Answer 1


You can use this code

add_action('adminmenu', function() {
    jQuery('#adminmenu .wp-has-current-submenu.wp-menu-open')
  • Thanks Vitauts but this isn't working for me. It may be the same, or similar, Javascript solution I mentioned in the question. I've tried adding the function via an "Add Functions" plugin, and putting it directly into the site's current theme's <i>function.php</i>. None of these work. Should I be putting it somewhere else.
    – Kevin4fm
    Commented Jan 24, 2020 at 12:14
  • I've discovered that the solution proposed by Vitauts does indeed work for me, but conflicts with the plugin "Admin Menu Editor". With this plugin activated, the fix stops working. Haven't yet worked out how to have both.
    – Kevin4fm
    Commented Aug 25, 2020 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.