# Paid Memberships Pro: Show Menu Items Only to Certain Levels

> Hides navigation menu items from anyone who doesn't hold a matching membership level, using a CSS class like wpide-level-2 on the item.

- Type: PHP
- Runs: Frontend only
- Category: [Memberships](https://wpide.com/library/category/memberships/)
- Tags: pmpro, menus, access
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/pmpro-menu-items-by-level/

## Code

```php
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
    return;
}

add_filter( 'wp_nav_menu_objects', function ( $items ) {
    $removed = array();

    foreach ( $items as $key => $item ) {
        $wanted = array();

        foreach ( (array) $item->classes as $class ) {
            if ( 'wpide-level-any' === $class ) {
                $wanted[] = 'any';
            } elseif ( preg_match( '/^wpide-level-(\d+)$/', $class, $m ) ) {
                $wanted[] = (int) $m[1];
            }
        }

        $hide = in_array( (int) $item->menu_item_parent, $removed, true );

        if ( $wanted && ! current_user_can( 'manage_options' ) ) {
            $levels = in_array( 'any', $wanted, true ) ? null : array_filter( $wanted, 'is_int' );
            $hide   = $hide || ! pmpro_hasMembershipLevel( $levels );
        }

        if ( $hide ) {
            $removed[] = (int) $item->ID;
            unset( $items[ $key ] );
        }
    }

    return $items;
} );
```

## Notes

Enable "CSS Classes" under Screen Options in Appearance > Menus. Use wpide-level-any for "any level".

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Paid Memberships Pro: Show Menu Items Only to Certain Levels" 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/
