Forums

[resolved] Customize WP Admin Bar (2 posts)

  1. angelazou
    Member
    Posted 5 months ago #

    Hi,

    I want to remove 2 items from the current WP admin bar, and add a sub-menu item to the my profile menu. Here is my code, and it doesn't work.

    function customize_admin_bar {
            global $wp_admin_bar;
            $wp_admin_bar->remove_menu('wp-logo');
            $wp_admin_bar->remove_menu('updates');
            $wp_admin_bar->add_menu(array(
                    'parent' => 'my-account',
                    'id' => 'support',
                    'title' => __('Support Center'),
                    'href' => "#")
            );
    }
    add_action( 'admin_bar_menu', 'customize_admin_bar' ); // I tried to user 'wp_before_admin_bar_render' instead of 'admin_bar_menu'

    I've searched every where, but it doesn't seem like WordPress has a codex page that provide the names of the menu items.

    Angela

  2. angelazou
    Member
    Posted 5 months ago #

    Actually, I got it figured just now. The following seems to be the answer I need. Just in case anyone is having the same problem as I am, you need separate functions to remove and add menus, each using different action hook.

    function remove_admin_bar_links() {
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu('wp-logo');
        $wp_admin_bar->remove_menu('updates');
    }
    add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
    
    function add_admin_bar_links() {
        global $wp_admin_bar;
        $wp_admin_bar->add_menu(array(
            'parent' => 'my-account-with-avatar',
            'id' => 'sup',
            'title' => __('Support Center'),
            'href' => "http://hosting.centilin.com/support/")
        );
    }
    add_action('admin_bar_menu', 'add_admin_bar_links');

    Angela

Reply

You must log in to post.

About this Topic