skip to Main Content

On the backend of a WordPress site, the admin menu looks like this:

Dashboard
Media
Pages
Pluginname
–– Edit
–– Short Code
–– Settings
–– FAQs

I would like to hide Pluginname/Settings from one admin. Since hovering over Pluginname/Settings shows https://url.xy/wp-admin/edit.php?post_type=pluginname&page=plg_settings , i added these lines of code to the functions.php file:

add_action( 'admin_init', 'my_remove_menu_pages' );
    function my_remove_menu_pages() {
        global $user_ID;
        if ( $user_ID == 2 ) {
            remove_menu_page( 'pluginname.php' , 'plg_settings.php' );
        }
    }

But this does not do anything.
Does anybody have advice for me?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to the hint from speshock I could find the solution. I had to use remove_submenu_page instead of remove_menu_page:

    remove_submenu_page( 'edit.php?post_type=pluginname' , 'plg_settings' );
    

  2. If your not looking at functions code I really recommend just using the admin menu editor. https://wordpress.org/plugins/admin-menu-editor/ It will allow you to change the name of the links, the icons, the permissions and so many more options. Hope that it works out for you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search