WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, I ran into an interesting issue while adding some admin menu bar links today. When adding links to a parent menu using something like:

// Add the parent menu
$wp_admin_bar->add_menu( array(
        'title' => 'Testing MENU',
        'href' => false,
        'id' => 'parent_id'

// Add the child menu $wp_admin_bar->add_menu( array( 'title' => 'My Child Label', 'href' => '#', 'parent' => 'parent_id' ));

The above code works great and as expected. But what if I wanted, for whatever reason, to add a second child menu item like this:

// Add another child menu
$wp_admin_bar->add_menu( array(
            'title' => 'My Child Label *',
            'href' => '#',
            'parent' => 'parent_id'

This will not work. The last menu item overrides the first. I understand that you would want to prevent duplicate titles in an admin menu, but this is technically NOT a duplicate title. To get it to work, I must add a non-special character (a-z,A-Z,0-9) to the end like this:

// Add another child menu
$wp_admin_bar->add_menu( array(
            'title' => 'My Child Label *1',
            'href' => '#',
            'parent' => 'parent_id'

It appears that the logic checking for duplicate labels is stripping any non-alphanumeric characters from the end of the title and then comparing that. Does anyone have any insight as to why this is? I can't think of any reason to not take the entire title into consideration.

Any thoughts?

share|improve this question
up vote 3 down vote accepted

You are not declaring an 'id' key. Without one, the id will default to a sanitized version of the 'title' value - hence your overwrite.

Declare a unique id element, and you should be golden.

That said, add_node is now the preferred method of achieving this.

share|improve this answer
Thanks! I hadn't thought about it requiring an id like that. And thanks for the heads-up about add_node. – Brett Shumaker Apr 9 '13 at 14:03

Your Answer


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.