WordPress.org

Ready to get started?Download WordPress

Forums

How to hide one menu item from Admin (appearance - menus) (3 posts)

  1. naastje
    Member
    Posted 1 year ago #

    Hey guys,

    Does anyone knows how to hide a specific menu from the Appearance -> Menus?

    I have few different menu tabs and I want to hide one menu tab so the menu won't be modified. nav-menus.php?action=edit&menu=3

    Is there any way to do that?

    I was trying to use Adminimize but it can't hide a specific navigation tab from there.

  2. naastje
    Member
    Posted 1 year ago #

    I was thinking it should be something in those lines:

    add_filter( 'wp_get_nav_menu_items', array( 'exclude_menu_items' )3 );

    What do you guys think?

  3. scattered810
    Member
    Posted 1 year ago #

    I use this to remove the portfolio menu item from "editors" just change "editor" to "admin" and then update the menu item you want to restrict. Put this in functions.php

    function custom_remove_menus(){
    
        // Get current user's data
        $current_user = wp_get_current_user();
        $user_id = $current_user->ID;
    
        // Check user's roles
        $user = new WP_User( $user_id );
        if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
            if( in_array( 'editor', $user->roles ) ) {
                // Remove menu items
                remove_menu_page( 'edit.php?post_type=portfolio');
            }
        }
    }
    
    add_action( 'admin_menu', 'custom_remove_menus' );

Topic Closed

This topic has been closed to new replies.

About this Topic