• Resolved franwess

    (@franwess)


    Hi there,

    Is there a way that I can hide a menu item from specific users? Not by role but by the specific user itself?

    Kind regards
    Francois Wessels

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @franwess

    Your question is too general with WordPress Menu question. This requires customisation on your end. You can try the code below but you will have to modify it to match your requirement:

    
    function wpse101120_exclude_menu_items( $items, $menu, $args ) {
        $user_id = get_current_user_id();
        $hide_menu = 168;
    
        // Iterate over the items to search and destroy
        foreach ( $items as $key => $item ) {
            if ( $item->object_id == $hide_menu && $user_id == 123 ) unset( $items[$key] );
        }
    
        return $items;
    }
    
    add_filter( 'wp_get_nav_menu_items', 'wpse101120_exclude_menu_items', null, 3 );
    

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @franwess

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide menu items for certain users’ is closed to new replies.