DevelopmentTips

Hello, WordPress 3.1! Now Let’s Clean Up That New WP Admin Bar

By February 23, 2011 4 Comments

WordPress 3.1 was released yesterday, hooray, huzzah. With it comes a new feature, the Drupal-esq Admin Bar which by default shows up for Administrators, even on the Front End. It is lovely with quick links to jump back to Edit whatever Page you are on, and more. Since it is brand new, I could not find much documentation for how to add/remove links in that WP Admin Bar, so I had to roll up my sleeves (figuratively – right now i am just wearing a tshirt), and figure it out myself.

After checking out the /wp-includes/admin-bar.php and associated /wp-includes/class-wp-admin-bar.php , it turns out that if you want to, say, Remove the “Comments” link from the WP Admin Bar, or Add a new link to Add New Media under the “Add New” section, we can do something like the following :

function nlk_admin_bar_render() {
global $wp_admin_bar;
// we can remove a menu item, like the COMMENTS link, just by knowing the right $id
$wp_admin_bar->remove_menu('comments');
// we can add a submenu item too
$wp_admin_bar->add_menu( array(
'parent' => 'new-content',
'id' => 'new_media',
'title' => __('Media'),
'href' => admin_url( 'media-new.php')
) );
}
// and we hook our function via
add_action( 'wp_before_admin_bar_render', 'nlk_admin_bar_render' );

What other items would be especially handy to have in this new Admin bar? Perhaps a button to show the Google Analytics click overlay on that page?

It already adds links to Menus and Widgetsl, under the Appearance dropdown, if your Theme supports those items, but how about finding out what specific Menus and Widget Areas are being shown on the particular Page you are on, and adding links to edit those directly, under the Edit Page dropdown?

And what about, since the ShareThis plugin already gives functionality to Like / Tweet / Post the page, what if we could pull up the metrics on those social activities too?

We’ll just have to wait and see what more comes out for this brand new Feature. And maybe, we at Ninthlink will have to create more custom plugin goodness for some of these new ideas too!

Alex Chousmith

Alex has been building with Ninthlink since '06, and a San Diegan since the turn of the century. A background of Mathematics – Computer Science / Interdisciplinary Computing & Arts from UCSD, plus Drupal / WordPress / jQuery / CSS3 / HTML5 / bass guitar / homebrew skill, powers him to get the job done, no matter what.

4 Comments

Leave a Reply