do_action_ref_array( 'admin_bar_menu', WP_Admin_Bar $wp_admin_bar )

Loads all necessary admin bar items.


Description

This is the hook used to add, remove, or manipulate admin bar items.


Top ↑

Parameters

$wp_admin_bar WP_Admin_Bar
The WP_Admin_Bar instance, passed by reference.

Top ↑

Source

File: wp-includes/admin-bar.php. View all references

do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );


Top ↑

Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by iqbalrony

    This hook is used to add the admin bar menu.

    Example:-

    add_action( 'admin_bar_menu', 'admin_bar_item', 500 );
    function admin_bar_item ( WP_Admin_Bar $admin_bar ) {
    	if ( ! current_user_can( 'manage_options' ) ) {
    		return;
    	}
    	$admin_bar->add_menu( array(
    		'id'    => 'menu-id',
    		'parent' => null,
    		'group'  => null,
    		'title' => 'Menu Title', //you can use img tag with image link. it will show the image icon Instead of the title.
    		'href'  => admin_url('admin.php?page=custom-page'),
    		'meta' => [
    			'title' => __( 'Menu Title', 'textdomain' ), //This title will show on hover
    		]
    	) );
    }
  2. Skip to note 2 content
    Contributed by Niloy

    Display custom menu only for the admin area and add dropdown menu

    function ci_admin_bar_item( WP_Admin_Bar $wp_admin_bar ) {
    
    	if ( !is_admin() ) {
    		return;
    	} // Display Menu only for wp-admin area
    
    	$menu_id = 'new-order-notify';
    
    	$wp_admin_bar->add_menu(
    		array(
    			'id'     => $menu_id,
    			'parent' => null , // use 'top-secondary' for toggle menu position.
    			'href'   => admin_url( 'admin.php?page=custom-page-slug' ),
    			'title'  => __( 'New Order Notification', 'text-domain' ),
    		)
    	);
    	$wp_admin_bar->add_menu(
    		array(
    			'parent' => $menu_id,
    			'title'  => __( 'Disable', 'text-domain'  ),
    			'id'     => 'new-order-notification-disable',
    			'href'   => admin_url( 'admin.php?page=custom-submenu-slug' ),
    
    		)
    	);
    
    }
    add_action( 'admin_bar_menu', 'ci_admin_bar_item', 100 );
  3. Skip to note 3 content

    This is how you can add admin bar menus to the right side.

    add_action( 'admin_bar_menu', 'admin_bar_item', 500 );
    function admin_bar_menus( WP_Admin_Bar $wp_admin_bar ) {
    
        $parent_slug = 'license-manager-wppt';
    
        $wp_admin_bar->add_menu( array(
            'id'    => $parent_slug,
            'parent' => 'top-secondary',
            'group'  => null,
            'title' => __( 'License Manager', 'lmfwppt' ),
            'href'  => admin_url('admin.php?page=license-manager-wppt'),
        ) );
    
    }

You must log in before being able to contribute a note or feedback.