do_action( 'wp_before_admin_bar_render' )

Fires before the admin bar is rendered.


Description Description


Source Source

File: wp-includes/admin-bar.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by a1iraza
    
    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.