# Search Box for the "My Sites" Admin Bar Menu

> Adds a filter field to the top of the toolbar's My Sites menu so super admins on large networks can type part of a name to find a site instantly.

- Type: PHP
- Runs: Run everywhere
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: admin-bar, my-sites, search
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-admin-bar-my-sites-filter/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

$wpide_min_sites = 10; // Show the filter above this many sites.

add_action( 'admin_bar_menu', function ( $bar ) use ( $wpide_min_sites ) {
    if ( empty( $bar->user->blogs ) || count( $bar->user->blogs ) <= $wpide_min_sites ) {
        return;
    }

    $bar->add_node( array(
        'parent' => 'my-sites-list',
        'id'     => 'wpide-my-sites-filter',
        'title'  => '<label class="screen-reader-text" for="wpide-my-sites-q">' . esc_html__( 'Filter sites' ) . '</label><input type="search" id="wpide-my-sites-q" placeholder="' . esc_attr__( 'Filter sites…' ) . '" style="width:94%;margin:4px 3%;padding:2px 6px;height:26px;line-height:1;color:#1d2327">',
        'meta'   => array( 'html' => '' ),
    ) );

    $filter = function () {
        ?>
<script>
document.addEventListener('input', function (e) {
    if (e.target.id !== 'wpide-my-sites-q') { return; }
    var q = e.target.value.toLowerCase();
    document.querySelectorAll('#wp-admin-bar-my-sites-list > li').forEach(function (li) {
        if (li.id === 'wp-admin-bar-wpide-my-sites-filter') { return; }
        li.style.display = li.textContent.toLowerCase().indexOf(q) === -1 ? 'none' : '';
    });
});
</script>
        <?php
    };

    add_action( 'wp_footer', $filter, 99 );
    add_action( 'admin_footer', $filter, 99 );
}, 19 ); // Before the list is built, so the field comes first.
```

## Notes

Appears only when you belong to more than ten sites; change $wpide_min_sites to show it sooner.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Search Box for the "My Sites" Admin Bar Menu" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
