How can I specify the position of an admin bar item added with $wp_admin_bar->add_menu() or add_node()?

If I am correct these are the default positions:

  • wp_admin_bar_wp_menu – 10
  • wp_admin_bar_my_sites_menu – 20
  • wp_admin_bar_site_menu – 30
  • wp_admin_bar_updates_menu – 40
  • wp_admin_bar_comments_menu – 60
  • wp_admin_bar_new_content_menu – 70
  • wp_admin_bar_edit_menu – 80

small code snippet from what I use:
add_action('admin_bar_menu', 'your_function_name', 10);

The 10 should bring it to the most left side in the adminbar.

At moment we are at WP version 3.8 and it still work like a charm.

Added example:

function add_item($admin_bar)  {
$args = array(
    'id'        => 'your-link', // Must be a unique name
    'title'     => 'Yoursite', // Label for this item
    'href'      =>__ ('your_site_url'),
    'meta'  => array(
        'target'=> '_blank', // Opens the link with a new tab
        'title' => __('Yoursite'), // Text will be shown on hovering
    ),
);
$admin_bar->add_menu( $args);
}
add_action('admin_bar_menu', 'add_item', 10); // 10 = Position on the admin bar

Leave a Comment