Support » Developing with WordPress » Logout link in dashboard panel (side menu)

  • Hello! I am trying to insert the link in the side panel menu (left side) for the user to log out. I already got the code and it works, but I can’t insert the icon. Can anyone adjust please? Thanks. The code is this:

    add_action(‘admin_init’, ‘text_domain_logout_link’);
    function text_domain_logout_link() {
    global $menu;
    $menu[9999] = array(__(‘Logout’), ‘read’, wp_logout_url());

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi OP..
    I’m trying to do the similar thing..I want the website to display “login register” when the user did not login and show logout when the user is logged in..I know I can add additional item to the menu, but it would not change to “log out” after user log in. I have been struggling to try to find a good way to do it…

    When loggedin you probably have a body class “logged-in”, (your theme may vary?), so customise your menu entries to add a class to each of them, say “show-loggedin” and “show-loggedout”, then add css like this:

    .show-loggedin { display: none;}
    .logged-in .show-loggedin { display: block;}
    .show-loggedout { display: block;}
    .logged-in .show-loggedout { display: none;}
    Moderator bcworkz


    Each menu item in the $menu array actually has 7 elements, you have only provided the first three. 4th is usually an empty string. 5th is the element classes. 6th is the element ID. 7th is the icon reference, such as ‘dashicons-admin-plugins’ for the plug icon.

    @sjjlinwp_loginout() source code can be examined to see how the correct URL is decided upon. While you cannot use the function directly because it outputs HTML, you can use similar logic to determine the proper URL and menu label.

    While your issue is similar to the OP’s, it’s not exactly the same. It rarely is no matter how it appears. Thus we ask members to always start their own topic instead of tagging onto other’s topics. Replies end up being confused when multiple issues are trying to be solved on the same thread.

    Thread Starter wpforever18


    Sucess! Thank you very much. The other elements were really missing.

    Moderator bcworkz


    You’re most welcome.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Logout link in dashboard panel (side menu)’ is closed to new replies.