WP_Admin_Bar::add_menu() WordPress Method

The WP_Admin_Bar::add_menu() method allows you to add a new menu item to the WordPress admin bar. This is useful if you want to add a new link or control to the admin bar.

WP_Admin_Bar::add_menu( array $node ) #

Adds a node (menu item) to the admin bar menu.


Parameters

$node

(array)(Required)The attributes that define the node.


Top ↑

More Information

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

Parameter $node takes an array of 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.

Top ↑

Source

File: wp-includes/class-wp-admin-bar.php

	public function add_menu( $node ) {
		$this->add_node( $node );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.