Loads all necessary admin bar items.
Description
This hook can add, remove, or manipulate admin bar items. The priority determines the placement for new items, and changes 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_bar
WP_Admin_Bar- The WP_Admin_Bar instance, passed by reference.
Source
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
This hook 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 working example to help save others some time and frustration.
CAVEAT: This code is tested and verified it works as of Sept 2023. However, WordPress is always changing, 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 make up. It should be self explanatory, in this caseadminbar-date-time
top-secondary
: tells WP to put this node / link / text on the right side500
inadd_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 timezone registered 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_time
and the result of that variable is what will display in the admin bar. If we wanted we could do'title' => __( 4 * 8 )
, and32
is what would be shown in the admin bar.href
: If you are making this a hyperlink then put the destination URL here. In this example,options-general.php
is the Settings > General page so you can change time and date if you wantFind the order that hooks and filters are called here: https://codex.wordpress.org/Plugin_API/Action_Reference
This is how you can add admin bar menus to the right side.