The new WordPress admin bar facilitates the access of backend and frontend to areas of the back end. Of course, this new control element of WordPress is expandable and can be adapted to the needs of the user. In some areas and for various needs, quick access to different areas is certainly interesting.
The newly created menus can be adapted as usual rights to the appropriate roles. A small example will demonstrate the integration.
Within the Admin Bar you can represent hierarchies, which are then coupled with a default Admin Bar with a mouse over effect. In the following example, a search on the WordPress Codex is integrated in the Admin bar. There are still things to do in terms of CSS, but I think this example points out some possibilities and can be used for your own ideas and requirements.
function wp_codex_search_form() { global $wp_admin_bar, $wpdb; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $codex_search = ''; /* Add the main siteadmin menu item */ $wp_admin_bar->add_menu( array( 'id' => 'codex_search', 'title' => __( 'Search the Codex', 'textdomain' ), 'href' => FALSE ) ); $wp_admin_bar->add_menu( array( 'parent' => 'codex_search', 'title' => $codex_search, 'href' => FALSE ) ); } add_action( 'admin_bar_menu', 'wp_codex_search_form', 1000 );
The function add_menu()
accepts certain parameters:
title
– default falsehref
– default false,parent
– default false – pass the ID value for a submenu of that menuid
– defaults to a sanitized title value.meta
– default false – array of any of the following options:array( 'html' => '', 'class' => '', 'onclick' => '', target => ''
);
Comments
8 responses to “Add Menus to the Admin Bar of WordPress”
Oh great, now every plugin will put a menu in the admin bar 🙁
Next stop: a plugin preventing others from cluttering the admin bar.
latz
[…] part of their ongoing series, WPEngineer has published a cool post that explains how to add new menus to the admin bar coming in WordPress 3.1. In the example, Frank adds a Codex Search button to the […]
@Latz Good point! I hope plugin developers will be reasonable.
Thanks for the tip. Please, what is that “micro” sign in your admin bar (on the left)?
I wanted to say “on the right”, sorry.
@Latz: yes, you are right; but i wish this for all menus and boxes inside the core; maybe a core plugin. But i will this include later in my plugin Adminimize, with this plugin i creat all backends for customer.
Very handy. I was able to modify this function to add a link to some “Theme Options” in the Appearance menu. Thank you!
// Add Theme Options to Admin Bar
function theme_options_link() {
global $wp_admin_bar, $wpdb;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'title' => __( 'Theme Options', 'urbanchurch' ), 'href' => get_bloginfo('url').'/wp-admin/themes.php?page=options.php' ) );
}
add_action('admin_bar_menu', 'theme_options_link', 1000);
//Frankie
hi, im using wordpress multi-site how can I display that bar. thanks
@Jonathan: Its a feature of WordPress 3.1