wp_admin_bar_render() WordPress Function
The wp_admin_bar_render() function is used to display the WordPress admin bar. The admin bar is a horizontal menu that is displayed at the top of the screen when a user is logged in to the WordPress admin area. The admin bar contains links to the WordPress admin dashboard, the current user's profile, and the WordPress site's front end.
wp_admin_bar_render() #
Renders the admin bar to the page based on the $wp_admin_bar->menu member var.
Description
This is called very early on the ‘wp_body_open’ action so that it will render before anything else being added to the page body.
For backward compatibility with themes not using the ‘wp_body_open’ action, the function is also called late on ‘wp_footer’.
It includes the ‘admin_bar_menu’ action which should be used to hook in and add new menus to the admin bar. That way you can be sure that you are adding at most optimal point, right before the admin bar is rendered. This also gives you access to the $post
global, among others.
Source
File: wp-includes/admin-bar.php
function wp_admin_bar_render() { global $wp_admin_bar; static $rendered = false; if ( $rendered ) { return; } if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { return; } /** * Loads all necessary admin bar items. * * This is the hook used to add, remove, or manipulate admin bar items. * * @since 3.1.0 * * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference. */ do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); /** * Fires before the admin bar is rendered. * * @since 3.1.0 */ do_action( 'wp_before_admin_bar_render' ); $wp_admin_bar->render(); /** * Fires after the admin bar is rendered. * * @since 3.1.0 */ do_action( 'wp_after_admin_bar_render' ); $rendered = true; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.4.0 | Called on 'wp_body_open' action first, with 'wp_footer' as a fallback. |
3.1.0 | Introduced. |