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 successfully managed to create admin bar item using this:

add_action('admin_bar_menu', 'toolbar_link_to_mypage', 999);
function toolbar_link_to_mypage($wp_admin_bar){
    global $wp_admin_bar;

    $theme_menu = array(
        'id' => 'theme_page',
        'title' => __('test', 'test'),
        'href' => 'http://mysite.com/my-page/',
        'meta' => array('class' => 'test')
    );

    $wp_admin_bar->add_node($theme_menu);
}

But I can't figure out what is the correct way to create an admin panel OPTIONS PAGE (not sub-menu item! Two answers are about sub-menus already) for 'href' => '', parameter. I can't simply use add_menu_page(); because that would attach it to left navigation as well. Any help would be great!

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

You have to create a new array for the new item and pass the parent parameter as the id of this already created item. In your case, the args array should be like this:

$args = array(
    'id' => 'my-item',
    'title' => 'My Item',
    'href' => '#',
    'parent' => 'theme_page',
    'meta' => array(
        'title' => __('Click Me'),
    ),
);

This post has a complete explanation of how and where you can add items to the admin bar and the usage of the parent parameter.

share|improve this answer
    
I didn't make myself clear enough. I know how to create sub-pages, too but I'm wondering how to create OPTIONS PAGE for admin bar item :) –  Paul Sep 6 '12 at 9:29
    
Options page? You mean you want to be able to add new menu items from an options page? –  Rutwick Gangurde Sep 6 '12 at 9:57
    
I can use add_menu_page(); to register new options page in left sidebar in admin panel. But I can't do that in top admin bar - I can only specify link. I'm looking for a way to create options page for each link in that bar. –  Paul Sep 6 '12 at 10:54
    
You add the page via the regular way, using add_menu_page, and then follow this: justintadlock.com/archives/2011/06/13/… tutorial to remove that page from the sidebar menu. Then, for the href part of your admin bar item, pass the url for the removed settings page. –  Rutwick Gangurde Sep 6 '12 at 12:30
    
Thanks! Great, it works! –  Paul Sep 6 '12 at 12:49
show 1 more comment

Here is the code that will work :

 add_action('admin_bar_menu', 'toolbar_link_to_mypage', 999);
function toolbar_link_to_mypage($wp_admin_bar){
    global $wp_admin_bar;

    $wp_admin_bar->add_menu(array(
        'id' => 'theme_page',
        'title' => __('test', 'test'),
        'href' => 'http://mysite.com/my-page/',
        'meta' => array('class' => 'test')
    ));

   $wp_admin_bar->add_menu(array(
        'id' => 'theme_page_child',
        'title' => __('Child test', 'child-test'),
        'href' => 'http://mysite.com/my-page/',
        'meta' => array('class' => 'child-test'),
    'parent' => 'theme_page'
    ));

}

In the first add_menu I have added a parent link In the next add_menu I am using another attribute 'parent' which is referring to the id of 'parent' here the 'parent' is 'theme_page' we created above.

share|improve this answer
    
Yes, but I'm wondering how to create OPTIONS PAGE for admin bar item. I know how to create sub-menu item. Any ideas? –  Paul Sep 6 '12 at 9:49
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.