Search Box for the Admin Menu
Adds a small filter box at the top of the admin menu that hides every menu and submenu item not matching what you type, handy on sites with dozens of plugin menus.
Opens WPIDE on
Code
add_action( 'admin_footer', function () {
?>
<style>
#wpide-menu-filter{margin:8px 10px;width:calc(100% - 20px);box-sizing:border-box;min-height:28px}
.folded #wpide-menu-filter{display:none}
#adminmenu li.wpide-hide{display:none}
#adminmenu.wpide-filtering .wp-submenu{position:static!important;display:block!important;box-shadow:none!important;margin:0!important}
</style>
<script>
( function () {
var menu = document.getElementById( 'adminmenu' );
if ( ! menu ) { return; }
var input = document.createElement( 'input' );
input.type = 'search';
input.id = 'wpide-menu-filter';
input.placeholder = 'Filter menu...';
input.setAttribute( 'aria-label', 'Filter admin menu' );
menu.parentNode.insertBefore( input, menu );
input.addEventListener( 'input', function () {
var term = input.value.trim().toLowerCase();
menu.classList.toggle( 'wpide-filtering', term !== '' );
menu.querySelectorAll( ':scope > li.menu-top' ).forEach( function ( item ) {
var top = ( item.querySelector( '.wp-menu-name' ) || item ).textContent.toLowerCase();
var subs = item.querySelectorAll( '.wp-submenu li:not(.wp-submenu-head)' );
var anySub = false;
subs.forEach( function ( sub ) {
var match = term === '' || top.indexOf( term ) !== -1 || sub.textContent.toLowerCase().indexOf( term ) !== -1;
sub.classList.toggle( 'wpide-hide', ! match );
anySub = anySub || ( match && term !== '' );
} );
item.classList.toggle( 'wpide-hide', term !== '' && top.indexOf( term ) === -1 && ! anySub );
} );
menu.querySelectorAll( ':scope > li.wp-menu-separator' ).forEach( function ( sep ) { sep.classList.toggle( 'wpide-hide', term !== '' ); } );
} );
input.addEventListener( 'keydown', function ( event ) {
if ( event.key === 'Escape' ) { input.value = ''; input.dispatchEvent( new Event( 'input' ) ); }
} );
} )();
</script>
<?php
} );
Notes
Press Escape to clear the filter; the box is hidden while the menu is collapsed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.