How to Add a Link to the Drop-Down User Menu in the Admin Bar?

I need to add a link to the drop-down user menu in the admin bar. Is there a hook or function for this?

WP admin bar user drop-down menu

2 Answers
2

You want to use $wp_admin_bar->add_node( $args ).

Below is a tested working example.

function wpse_add_toolbar_edit($wp_admin_bar) { 
    $wp_admin_bar->add_node( array(
        'id'        => 'mylink',
        'title' => 'My New Link',
        'href' => 'mailto:support@domain.com',
        'parent' => 'user-actions'
    ) );
}

add_action('admin_bar_menu', 'wpse_add_toolbar_edit', 999);

Note: The parent param adds the link to an existing ID. If you need to find the correct ID to add your new link to you can var_dump($wp_admin_bar); and look through the output for the correct ID.

Leave a Comment