do_action( ‘wp_before_admin_bar_render’ )

Fires before the admin bar is rendered.

More Information

The wp_before_admin_bar_render action allows developers to modify the $wp_admin_bar object before it is used to render the Toolbar to the screen.

Please note that you must declare the $wp_admin_bar global object, as this hook is primarily intended to give you direct access to this object before it is rendered to the screen.

Source

do_action( 'wp_before_admin_bar_render' );

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

  1. Skip to note 5 content

    (From Codex)
    Add a Submenu Item

    function my_tweaked_admin_bar() {
    	global $wp_admin_bar;
    
    	//Add a link called 'My Link'...
    	$wp_admin_bar->add_menu( array(
    		'id'    => 'my-link',
    		'title' => 'My Link',
    		'href'  => admin_url()
    	));
    
    	//THEN add a sub-link called 'Sublink 1'...
    	$wp_admin_bar->add_menu( array(
    		'id'    => 'my-link-sub-1',
    		'title' => 'Sublink 1',
    		'href'  => admin_url(),
    		'parent'=>'my-link'
    	));
    }
    add_action( 'wp_before_admin_bar_render', 'my_tweaked_admin_bar' );
  2. Skip to note 6 content
    if ( !function_exists('add_custom_admin_bar_menu') ) {
    
    	add_action( 'wp_before_admin_bar_render', 'add_custom_admin_bar_menu');
    
    	function add_custom_admin_bar_menu()
    
    	{
    		global $wp_admin_bar;
    
    		$args = [
    			'id' => 'custom_admin_bar_menu_id', // id must be unique
    			'title' => 'Custom Menu', // title for display in admin bar
    			'href' => 'http://add-your-link-here.com', // link for the achor tag
    
    			// meta for link e.g: class, target, and custom data attributes etc
    			'meta' => [ 
    				'class' => 'custom_class', // your custom class
    			],
    		];
    		$wp_admin_bar->add_menu($args);
    
    		$args_submenu_1 = [
    			'id' => 'cusotm-sub-menu-1',
    			'title' => 'Sub menu-1',
    			'parent' => 'custom_admin_bar_menu_id', // add parent id in which you want to add sub menu
    			'href' => 'http://add-your-link-here.com',
    			'meta' => [
    				'class' => 'custom_sub_menu_class',
    			],
    		];
    		$wp_admin_bar->add_menu($args_submenu_1);
    
    		$args_submenu_2 = [
    			'id' => 'cusotm-sub-menu-2',
    			'title' => 'Sub menu-2',
    			'parent' => 'custom_admin_bar_menu_id', // add parent id in which you want to add sub menu
    			'href' => 'http://add-your-link-here.com',
    			'meta' => [
    				'class' => 'custom_sub_menu_class',
    			],
    		];
    		$wp_admin_bar->add_menu($args_submenu_2);
    		
    	}
    
    }

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