Add Menus to the WordPress Toolbar

Add menu items to the WordPress Toolbar, the little black bar at the top of the page when logged in. An example would be if you wanted to add a list of custom post types to a standalone dropdown. Remember to change your “custom_post_type”.

// Add new node
add_action( 'admin_bar_menu', 'add_admin_links', 500 );

function add_admin_links( $wp_admin_bar ) {

  $args = array(
    'id' => 'admin-links',
    'title' => __( 'Add Things' ),
    'href' => false
  );

  $wp_admin_bar->add_node($args);
  
  $blogurl = get_bloginfo('url');

// Add child items
$wp_admin_bar->add_node( array(
    'parent' => 'admin-links',
    'title' => 'Add a Custom Post Type',
    'href' => $blogurl . '/wp-admin/post-new.php?post_type=custom_post_type',
    'meta' => FALSE) );
$wp_admin_bar->add_node( array(
    'parent' => 'admin-links',
    'title' => 'Add a Page',
    'href' => $blogurl . '/wp-admin/post-new.php?post_type=page',
    'meta' => FALSE) );

}