Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Hide admin "Pages" menu item WordPress

  • SOLVED

Hi, does anyone knows how to hide the admin menu's "Pages" section. I've been using:


add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu()
{
echo '
<style>
#menu-pages {
display: none;
}
</style>
';
}


but this seems to mess the design in IE and I couldn't find why

Answers (3)

2010-11-26

idt answers:

You can try the method suggested here instead: http://www.wprecipes.com/how-to-remove-menus-in-wordpress-dashboard

2010-11-27

Jermaine Oppong answers:

Specifically you would need to use this code:


function remove_menus () {
global $menu;
$restricted = array( __('Pages'));
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');

2010-11-27

Bob answers:

If you prefer to base it on user role this is a very easy function, simply replace 'username' with an actual username. You can also just delete or comment out the pages you still want in, in your case comment out everything except __('Pages').




function remove_menus()
{
global $menu;
global $current_user;
get_currentuserinfo();

if($current_user->user_login == 'username')
{
$restricted = array(__('Posts'),
__('Media'),
__('Links'),
__('Pages'),
__('Comments'),
__('Appearance'),
__('Plugins'),
__('Users'),
__('Tools'),
__('Settings')
);
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}// end while

}// end if
}
add_action('admin_menu', 'remove_menus');


You can also change line 7 to if($current_user->user_login != 'admin') which would not show any menu items if your not admin ( can replace admin with any username).