do_action( 'wp_before_admin_bar_render' )
Fires before the admin bar is rendered.
Description Description
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
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); } }Expand full source codeCollapse full source code