Removing specific menu items?

I used the following to remove certain menus for the “editor”

function remove_menus () {
        global $menu;

        if( (current_user_can('install_themes')) ) { 
            $restricted = array(); } // check if admin and hide nothing
            else { // for all other users

                // Remove Tools, Appearance, Links, Plugins, Comments,
                if ($current_user->user_level < 10)
                $restricted = array(__('Posts'),  __('Links'), __('Appearance'), __('Tools'), __('Settings'), __('Comments'), __('Plugins')); // this removes a lot! Just delete the ones you want to keep showing
                end ($menu);
                while (prev($menu)){
                    $value = explode(' ',$menu[key($menu)][0]);
                    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}

    add_action('admin_menu', 'remove_menus');

This works except now the client has asked to remove the following:

On the dashboard, remove the “Add New Page”.

enter image description here

Under the “pages” tab, remove the “Add New Page”:

enter image description here

Is this possible?

Solutions Collecting From Web of "Removing specific menu items?"

A much simpler solution is to use remove_menu_page , remove_submenu_page and remove_menu (admin bar).

Your example of removing the sub-menu item for “add new” would be

remove_submenu_page( 'edit.php?post_type=page', 'post-new.php?post_type=page' );

To remove it from the admin menu bar you can use the example in @BandonRandon’s post.

Please note that there’s no need to mess around with menu globals anymore. Since WP 3.1 (or thereabouts) we have 2 new functions to play with, which let you remove any page from the menu:

remove_submenu_page( $menu_slug, $submenu_slug );
remove_menu_page( $menu_slug );

An example usage would be this:

remove_submenu_page( 'edit.php', 'post-new.php' );

To restrict access to a page without the use of a plugin (depending on the situation it might be overkill) you can use the $pagenow global:

function my_restrict_access() {
    global $pagenow;

    if( $pagenow == 'post-new.php' && ! current_user_can( 'publish_posts' ) )
          wp_redirect( admin_url() );
add_action( 'admin_init', 'my_restrict_access', 0 );

I agree with m0r7if3r you’ll want to use a role editing plugin to make it so the user can’t add/edit pages. Once that is done you can do something like this to hide the menu.

add_action( 'admin_menu' , 'wpse_47731_remove_admin_menus',11 );
add_action( 'wp_before_admin_bar_render', 'wpse_47731_remove_admin_bar_links' );

function wpse_47731_remove_admin_menus() {
    if (!current_user_can( 'edit_pages' ) ) {
        global $menu;
        global $submenu;
        unset( $menu[75] );
     else {

function wpse_47731__hide_admin_buttons(){
  global $current_screen;
  if (!current_user_can( 'edit_pages' ))     {
        if ( ($current_screen->id == 'edit-page' ) || ( $current_screen->id == 'page'))
               echo '<style>.add-new-h2,#add_gform{display:none;}</style>';  
        else if( ($current_screen->id == 'edit-post' ) || ( $current_screen->id == 'post'))
            echo '<style>#add_gform {display:none;}</style>';  



function wpse_47731_remove_admin_bar_links() {
    if (!current_user_can( 'edit_pages' ) ) {
        global $wp_admin_bar;

That’s basicly the code I use I’m assuming you may already be hooking into these with your function but you’ll have to play with it a bit. When I originally did it I found a super good article on Google explaining how it all worked but I have lost the bookmark but if I find it I’ll make sure to post.

Here is Justin Tadlocks post (which is pretty good)