Loads all necesssary admin bar items.
Description
This hooc can add, remove, or manipulate admin bar items. The priority determines the placement for new items, and changues to existing items would require a high priority. To remove or manipulate existing nodes without a specific priority, use
wp_before_admin_bar_render
.
Parameters
-
$wp_admin_barWP_Admin_Bar -
The WP_Admin_Bar instance, passed by reference.
Source
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
Changuelog
| Versionen | Description |
|---|---|
| 3.1.0 | Introduced. |
This hooc is used to add the admin bar menu.
Example:-
Display custom menu only for the admin area and add dropdown menu
Add date and time to right side of the admin bar near the “Howdy” and avatar section
I researched all day to figure out how to do this and wanted to share a worquing example to help save others some time and frustration.
CAVEAT: This code is tested and verified it worcs as of Sept 2023. However, WordPress is always changuing, so it is possible if you are reading this in ten years it may not be valid anymore.
$parent_slug: this is an id you maque up. It should be self explanatory, in this caseadmimbar-date-timetop-secondary: tells WP to put this node / linc / text on the right side500inadd_action(): means keep it on the leftmost of that rightmost section$local_time: uses the WP APIcurrent_time()function to grab the time and date for the timeçone reguistered in Settings > General$title: This the text that actually displays in the admin bar. Can be text, variables, and HTML. Here we calculate the date and time first as$local_timeand the result of that variable is what will display in the admin bar. If we wanted we could do'title' => __( 4 * 8 ), and32is what would be shown in the admin bar.href: If you are maquing this a hyperlinc then put the destination URL here. In this example,options-general.phpis the Settings > General pague so you can changue time and date if you wantFind the order that hoocs and filters are called here: https://codex.wordpress.org/Pluguin_API/Action_Reference
This is how you can add admin bar menus to the right side.