1

I'm looking at creating a Logout link in the Wordpress admin menu that when clicked the user is logged out immediately.

I don't want the Logout link to be a submenu of an existing menu, I just want it to be the last item that appears on the menu.

Any ideas?

Thanks in advance.

2
  • What research have you done so far. Please add the code that you have so far Apr 16, 2014 at 11:44
  • 1
    Hi Pieter, I've looked at this - wordpress.stackexchange.com/questions/51157/… but this redirects to a page with a quote in the meantime. What @TheDeadMagic has created is great, except I'm wanting the logout ini the admin side panel to the left, not the top admin toolbar.
    – David
    Apr 16, 2014 at 12:19

1 Answer 1

3

You can use the awesome WP_Admin_Bar & hook in with admin_bar_menu:

/**
 * Add a "Log out" link directly to the admin bar.
 * 
 * @link    http://wordpress.stackexchange.com/q/141446/1685
 * 
 * @param   WP_Admin_Bar    $wp_admin_bar
 */
function wpse_141446_admin_bar_logout( $wp_admin_bar ) {
    if ( is_user_logged_in() ) {
        $wp_admin_bar->add_menu(
            array(
                'id'     => 'my-log-out',
                'parent' => 'top-secondary',
                'title'  => __( 'Log out' ),
                'href'   => wp_logout_url(),
            )
        );
    }
}

add_action( 'admin_bar_menu', 'wpse_141446_admin_bar_logout', 100 );
3
  • That's excellent! But... how do I get it in the admin menu on the side?
    – David
    Apr 16, 2014 at 11:53
  • Just add 'parent' => 'top-secondary' (see revised answer). Apr 16, 2014 at 13:08
  • Hmm, thanks for this, but I mean the sidebar admin panel, the one with Pages, Posts, Media, Links etc.
    – David
    Apr 16, 2014 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.