Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I see many questions have been asked about adding something to the admin bar, but still I can't get a new 'parent' admin-bar item for Advanced Custom Fields to work. The admin bar doesn't show up if I add this to my functions.php:

function my_theme_admin_bar_render() {
$wp_admin_bar->add_menu( array(
    'parent' => 'Advanced Custom Fields',
    'id' => 'acf',
    'title' => __('Advanced Custom Fields'),
    'href' => admin_url( 'edit.php?post_type=acf')
) );
}   
add_action( 'wp_before_admin_bar_render', 'my_theme_admin_bar_render' );

How can I get this new admin bar item to work?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

I don't think you'll need the parent for a root menu item while using add_menu. But make sure to get the hint in the Codex:

Note: The Admin Bar is replaced with the toolbar since WordPress Version 3.3. The preferred way to add items to the toolbar is with add_node().

Give it a try:

add_action( 'admin_bar_menu', 'toolbar_link_to_acf', 999 );

function toolbar_link_to_acf( $wp_admin_bar ) {
  $args = array(
    'id' => 'acf',
    'title' => 'Advanced Custom Fields',
    'href' => admin_url('edit.php?post_type=acf'),
    'meta' => array('class' => 'toolbar-acf')
  );

  $wp_admin_bar->add_node($args);
}
share|improve this answer
    
and adding admin_url to the href was the last trick to get it working :) Thx sven, works like a charm! –  Forza May 28 '13 at 0:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.