How to hook theme of the main system menu in drupal 7 to display only some of the elements? I want to modify the main system menu in Drupal 7. Actually I want to display only some specific elements of the menu and hide some other specific elements, in a given case (which I will implement by a if or switch statement in a function).

What is the easiest way to do this ? And how to do it ? Can you give me an example ?

I have read that using hook_theme or hook_menu can be done, but I have no idea how to do this.
There are different levels to alter the system menu. If you want to add a top level container like drupal commerce does for the admin shop section, you need to add a menu item with hook menu like this:

// Top level "Store" container.
$items['admin/commerce'] = array(
  'title' =&gt; 'Store',
  'description' =&gt; 'Administer your store.',
  'page callback' =&gt; 'system_admin_menu_block_page',
  'access arguments' =&gt; array('access administration pages'),
  'file path' =&gt; drupal_get_path('module', 'system'),
  'file' =&gt; 'system.admin.inc',
  'weight' =&gt; -7,
);


system_admin_menu_block_page is what will do the job, of making it a part of the system menu.

If you want to make the menu appear under one of the sections, like configuration etc, you just need to adjust your path in hook_menu, fx

$items['admin/config/section'] = array(...);


Every time you want to create a section that should hold other menu items, simply add

'page callback' =&gt; 'system_admin_menu_block_page',
'access arguments' =&gt; array('access administration pages'),
'file' =&gt; 'system.admin.inc',
'file path' =&gt; drupal_get_path('module', 'system'),


When creating a menu item in a section, just create a normal menu item.

Update
Since the menu structure is cached, you can't alter the menu by a per user scenario. But there are still some methods available.


Since menus are only displayed if the user has access, you could create a custom access control function for all the menus and put your logic in there.
You could also try to do this in the theming layer, and alter the output to only display the desired menus. I haven't tried this in Drupal 7, but generally, altering the output of menus this way is hard, as the menu system is quite complex.


If you need to alter the menus, to change the access control, you should use hook_menu_alter.