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 have a plugin that adds custom admin bar items, but I'd like them to appear all the way to the left. I know I can add and remove menu items with $wp_admin_bar->add_menu() etc, but how can I reorder them?

Edit: It looks like the admin bar menu item orders are defined in wp-includes/class-wp-admin-bar.php, but I can't figure out how to change this order from within my plugin function.

            add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 );
            add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
            add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
            add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 );
share|improve this question

1 Answer 1

function custom_menu_order($menu_ord) {  
    if (!$menu_ord) return true;  

    return array(  
        'index.php', // Dashboard  
        'separator1', // First separator  
        'edit.php', // Posts  
        'upload.php', // Media  
        'link-manager.php', // Links  
        'edit.php?post_type=page', // Pages  
        'edit-comments.php', // Comments  
        'separator2', // Second separator  
        'themes.php', // Appearance  
        'plugins.php', // Plugins  
        'users.php', // Users  
        'tools.php', // Tools  
        'options-general.php', // Settings  
        'separator-last', // Last separator  
    );  
}  
add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order  
add_filter('menu_order', 'custom_menu_order');  
share|improve this answer
    
It would add value to the solution if you present it with some explanations. –  Maruti Mohanty Dec 9 '13 at 20:44
    
I tried echoing $menu_ord, but it doesn't return anything, so it might be empty. Also, my admin bar items are links with IDs, created with $wp_admin_bar->add_menu(), so I'm not sure I can reference them with a .php entry. –  Jon Dec 10 '13 at 15:12
    
Does it work for any items starting with admin.php like admin.php?page=custom_settings_page? –  Chittaranjan Dec 12 '13 at 13:19

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.