Add Links to the Admin Bar

It can be really useful to add some custom links to the Admin Bar. Like, perhaps to the hidden-yet-awesome options.php page.

add_action( 'admin_bar_menu', 'additional_admin_bar_menu', 70 );
function additional_admin_bar_menu( $wp_admin_bar ) {
    if ( current_user_can('manage_options') )
    $wp_admin_bar->add_menu( array( 'id' => 'all-settings', 'title' => __('All Settings'), 'href' => admin_url('options.php') ) );
}

If you want to add a sub-menu item, you must add a “parent” parameter, and its value should match the ID of the parent element.

add_action( 'admin_bar_menu', 'additional_admin_bar_menu_child', 70 );
function additional_admin_bar_menu_child( $wp_admin_bar ) {
        $wp_admin_bar->add_menu( array( 'parent' => 'all-settings', 'id' => 'google', 'title' => __('Google'), 'href' => 'http://google.com' ) );
}

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: