do_action_ref_array( 'admin_bar_menu', WP_Admin_Bar $wp_admin_bar )
Loads all necessary admin bar items.
Description
This is the hook used to add, remove, or manipulate admin bar items.
Parameters
-
$wp_admin_bar
WP_Admin_Bar -
The WP_Admin_Bar instance, passed by reference.
Source
File: wp-includes/admin-bar.php
.
View all references
do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
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 wantThis is how you can add admin bar menus to the right side.
Top ↑
Feedback
When this code is added to a Code Snippet this error appears and breaks the editor area of the dashboard: Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function “admin_bar_item” not found or invalid function name in T:\csite_30_elijahStreams\_dev\wp-includes\class-wp-hook.php on line 310 ( ! ) TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function “admin_bar_item” not found or invalid function name in T:\csite_30_elijahStreams\_dev\wp-includes\class-wp-hook.php on line 310 — By Eric Hepperle —
Find the order that hooks and filters are called here: https://codex.wordpress.org/Plugin_API/Action_Reference