spacerabbit
spacerabbit

Reputation: 15

WordPress admin menu: custom logout link shows as submenu item instead of menu item

I added a custom logout link to my WP admin menu, but instead of appearing as a top-level menu item, it is displayed as a submenu item (smaller font size, left padding). The link itself works perfectly though. Any ideas how the code can be changed? Thanks!

current admin menu

The code I use is from this thread.

add_action('admin_init', 'text_domain_logout_link');


function text_domain_logout_link() {
    global $menu;
    $menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());
}

Upvotes: 0

Views: 349

Answers (1)

Akhtarujjaman Shuvo
Akhtarujjaman Shuvo

Reputation: 690

Can you try this?:

add_action('admin_menu', 'text_domain_logout_link');
function text_domain_logout_link() {
    global $menu;
    $menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());
}

Tested and works on my wordpress

enter image description here

Updated: If you want to show it to top-level then use this code:

add_action('admin_menu', 'text_domain_logout_link');
function text_domain_logout_link() {
    global $menu;
    $menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());

    // add class
    $menu[9999][4] =  "menu-top toplevel_page_menu";

    // Add Icon
    $menu[9999][6] =  "dashicons-update";

}

So it will look like this:

enter image description here

Upvotes: 0

Related Questions