WordPress: Customize the Admin Bar in 3.3

In WordPress 3.1 and 3.2, a simple call could be made to clear out and kill the infamous “Admin Bar”. In 3.3, however, it’s now a necessary part of the dashboard. But what if we don’t want everyone to see everything?

The following clip will hide the menu options that are undesirable for users who are below Admin level. To hide an option that is visible when using this, simply uncomment the corresponding line, or to show an option that isn’t visible, simply comment that line.

global $wp_admin_bar;
if ( !current_user_can( 'install_themes' ) ) {
     $wp_admin_bar->remove_node( 'wp-logo' );
          // or individually remove its children
          // $wp_admin_bar->remove_node( 'about' );
          // $wp_admin_bar->remove_node( 'wporg' );
          // $wp_admin_bar->remove_node( 'documentation' );
          // $wp_admin_bar->remove_node( 'support-forums' );
          // $wp_admin_bar->remove_node( 'feedback' );
     $wp_admin_bar->remove_node( 'site-name' );
     $wp_admin_bar->remove_node( 'comments' );
     $wp_admin_bar->remove_node( 'new-content' );
          // or individually remove its children
          // $wp_admin_bar->remove_node( 'new-post' );
          // $wp_admin_bar->remove_node( 'new-media' );
          // $wp_admin_bar->remove_node( 'new-link' );
          // $wp_admin_bar->remove_node( 'new-page' );
          $wp_admin_bar->remove_node( 'user-info' );
          $wp_admin_bar->remove_node( 'edit-profile' );

And don’t forget your call to make the magic happen. In my case, I named the function containing the code above as “custom_admin_bar”.

add_action('wp_before_admin_bar_render', 'custom_admin_bar');

I saw bits of this somewhere, and pieced it together, but I don’t recall where. I’m currently using this in a plugin, but it may work in a theme’s functions.php file as well.