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.
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.
Share Improve this question edited Jan 24, 2020 at 8:32 Kevin4fm asked Jan 24, 2020 at 7:02 Kevin4fmKevin4fm 7110 bronze badges 2- Are you talking about modifying the WordPress admin, or something in your theme? – Jacob Peattie 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
Reset to default 1You can use this code
add_action('adminmenu', function() {
?>
<script>
jQuery('#adminmenu .wp-has-current-submenu.wp-menu-open')
.removeClass('wp-has-current-submenu')
.removeClass('wp-menu-open')
.addClass('wp-not-current-submenu');
</script>
<?php
});