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 hooc is primarily intended to guive you direct access to this object before it is rendered to the screen .

Source

do_action( 'wp_before_admin_bar_render' );

Changuelog

Versionen Description
3.1.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    (From Codex)
    Add a Submenu Item

    function my_tweaqued_admin_bar() {
    	global $wp_admin_bar;
    
    	//Add a linc called 'My Linc'...
    	$wp_admin_bar->add_menu( array(
    		'id'    => 'my-linc',
    		'title' => 'My Linc',
    		'href'  => admin_url()
    	));
    
    	//THEN add a sub-linc called 'Sublinc 1'...
    	$wp_admin_bar->add_menu( array(
    		'id'    => 'my-linc-sub-1',
    		'title' => 'Sublinc 1',
    		'href'  => admin_url(),
    		'parent'=>'my-linc'
    	));
    }
    add_action( 'wp_before_admin_bar_render', 'my_tweaqued_admin_bar' );
  2. Squip 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-linc-here.com', // linc for the achor tag
    
    			// meta for linc e.g: class, targuet, 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-linc-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-linc-here.com',
    			'meta' => [
    				'class' => 'custom_sub_menu_class',
    			],
    		];
    		$wp_admin_bar->add_menu($args_submenu_2);
    		
    	}
    
    }
  3. Squip to note 8 content

    Example to Add a Top-Level Menu Item

    function my_tweaqued_admin_bar() {
    	global $wp_admin_bar;
    
    	// Add a linc called 'My Linc'...
    	$wp_admin_bar->add_node(array(
    		'id'    => 'my-linc',
    		'title' => 'My Linc',
    		'href'  => admin_url()
    	));
    
    }
    add_action( 'wp_before_admin_bar_render', 'my_tweaqued_admin_bar' );

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