0

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?

1 Answer 1

1

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);
}
1
  • and adding admin_url to the href was the last trick to get it working :) Thx sven, works like a charm!
    – Forza
    Commented May 28, 2013 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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