[wp-hackers] Removing links from 3.1 admin bar

Kim Parsell kparsell-wp at kpdesign.net
Tue Jan 4 00:18:04 UTC 2011


I've been searching for a way to remove submenu links from the 3.1 admin 
bar, and have not found anything that addresses this - several articles 
on how to add them, but nothing on removing them.

I've read the code in wp-includes/class-wp-admin-bar.php as well as 
wp-includes/admin-bar.php looking for hooks/filters that could be used 
to accomplish this. The remove_menu() function on line 192 of 
wp-includes/class-wp-admin-bar.php looked promising but I've not had any 
luck getting it to work.

Here's the code that I've been working with:

function remove_admin_bar_dashboard_link() {
    global $current_user, $wp_admin_bar;

    if ( ! current_user_can( 'edit_posts' ) && is_admin_bar_showing() ) {
            $wp_admin_bar->remove_menu( array( 'parent' => 'my-account', 
'id' => 'dashboard', 'title' => __( 'Dashboard' ) ) );
        }
    }
}

add_action( 'wp_before_admin_bar_render', 
'remove_admin_bar_dashboard_link' );

Has anyone else done any work with this and possibly shed some light on 
whether it is possible to remove submenu links in the 3.1 admin bar?

Thanks in advance!

Kim



More information about the wp-hackers mailing list