WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Class Reference/WP Admin Bar/add menu

Description

Create or add new items into the Admin bar.

This is not a function. It is a method of the $wp_admin_bar global (an instance of WP_Admin_Bar), which may not exist except during the 'admin_bar_menu' hook.

Note: The Admin Bar is replaced with the Toolbar since WordPress Version 3.3. The preferred way to add items to the toolbar is with add_node().

Initial items in the Admin Bar are($menu_id):

  • my-account-with-avatar - Dashboard, User settings
  • new-content - Short-cut to all custom post types and original ones
  • comments - Comments moderation
  • appearance - Theme selection and Widgets

Usage

<?php $wp_admin_bar->add_menu$args ?>

Parameters

$args
(array) (required) An array of arguments.
Default: None

Arguments

id
(string) (required) The ID of the node.
Default: false
title
(string) (optional) The text that will be visible in the Toolbar. Including html tags is allowed.
Default: false
parent
(string) (optional) The ID of the parent node.
Default: false
href
(string) (optional) The 'href' attribute for the link. If 'href' is not set the node will be a text node.
Default: false
group
(boolean) (optional) This will make the node a group (node) if set to 'true'. Group nodes are not visible in the Toolbar, but nodes added to it are. See add_group().
Default: false
meta
(array) (optional) An array of meta data for the node.
Default: array()
  • 'html' - The html used for the node.
  • 'class' - The class attribute for the list item containing the link or text node.
  • 'rel' - The rel attribute.
  • 'onclick' - The onclick attribute for the link. This will only be set if the 'href' argument is present.
  • 'target' - The target attribute for the link. This will only be set if the 'href' argument is present.
  • 'title' - The title attribute. Will be set to the link or to a div containing a text node.
  • 'tabindex' - The tabindex attribute. Will be set to the link or to a div containing a text node.

Example

See: add_node

Change Log

Source File

add_menu() is located in wp-includes/class-wp-admin-bar.php.

Resources

Related Articles

Toolbar API

See also index of Function Reference and index of Template Tags.