WP_Admin_Bar::add_group( array $args )
Add a group to a menu node.
Description Description
Parameters Parameters
- $args
-
(array) (Required) Array of arguments for adding a group.
- 'id'
(string) ID of the item. - 'parent'
(string) Optional. ID of the parent node. Default 'root'. - 'meta'
(array) Meta data for the group including the following keys: 'class', 'onclick', 'target', and 'title'.
- 'id'
Source Source
File: wp-includes/class-wp-admin-bar.php
final public function add_group( $args ) {
$args['group'] = true;
$this->add_node( $args );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Adding a group to a parent node
This example adds a parent node, child nodes and a group to the toolbar.
add_action( 'admin_bar_menu', 'add_nodes_and_groups_to_toolbar', 999 ); function add_nodes_and_groups_to_toolbar( $wp_admin_bar ) { // add a parent item $args = array( 'id' => 'parent_node', 'title' => 'parent node' ); $wp_admin_bar->add_node( $args ); // add a child item to our parent item $args = array( 'id' => 'child_node', 'title' => 'child node', 'parent' => 'parent_node' ); $wp_admin_bar->add_node( $args ); // add a group node with a class "first-toolbar-group" $args = array( 'id' => 'first_group', 'parent' => 'parent_node', 'meta' => array( 'class' => 'first-toolbar-group' ) ); $wp_admin_bar->add_group( $args ); // add an item to our group item $args = array( 'id' => 'first_grouped_node', 'title' => 'first group node', 'parent' => 'first_group' ); $wp_admin_bar->add_node( $args ); // add another child item to our parent item (not to our first group) $args = array( 'id' => 'another_child_node', 'title' => 'another child node', 'parent' => 'parent_node' ); $wp_admin_bar->add_node( $args ); }Expand full source codeCollapse full source code
The output from this example in the toolbar will be: