0

I've added some custom menù pages to my WordPress dashboard using the add_menu_page() function. I need to remove these pages for super admin roles, but the remove_menu_page() seems not working. This is the code I have in my plugin

    function remove_default_menu_pages()
    {
        if( !current_user_can( 'manage_options' ) ){
            remove_menu_page( 'index.php' );
            remove_menu_page( 'edit.php?post_type=page' );
            remove_menu_page( 'edit.php' );
            remove_menu_page( 'edit-comments.php' );
            remove_menu_page( 'themes.php' );
            remove_menu_page( 'plugins.php' );
            remove_menu_page( 'users.php' );
            remove_menu_page( 'upload.php' );
            remove_menu_page( 'tools.php' );
            remove_menu_page( 'options-general.php' );
            remove_menu_page( 'profile.php' );
            //remove_menu_page( 'admin.php?page=authorizer' );
        } 
        //TOFIX
        remove_menu_page( 'admin.php?page=dashboard' );
        remove_menu_page( 'admin.php?page=messages' );
        remove_menu_page( 'admin.php?page=contacts' );
        remove_menu_page( 'admin.php?page=calendar' );
        remove_menu_page( 'admin.php?page=filemanager' );
        remove_menu_page( 'admin.php?page=learning-center' );
        remove_menu_page( 'admin.php?page=polls' );
    }
    add_action( 'admin_menu', 'remove_default_menu_pages' );

Is there something wrong into the code or I need a separate function?

1 Answer 1

0

Try to use the slug of the pages as parameter, e.g. remove_menu_page( 'dashboard' ); instead of remove_menu_page( 'admin.php?page=dashboard' );.

1
  • Already tried but not works, I suspect there is more to investigate or a different hook to use
    – ICTDEV
    Sep 18, 2023 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.