Add logout link to WordPress admin dashboard left sidebar menu

痴心易碎 提交于 2021-02-18 19:40:51

问题


I want to add logout link(button) in the left side of my wordpress admin dashboard. Like on the picture.. How can I do it?


回答1:


UPDATED

You can achive this using admin_init action hook and global $menu.

Here is this code:

add_action('admin_init', 'text_domain_logout_link');

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

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and fully functional.


References:

  • admin_init
  • global $menu
  • Customizing Your WordPress Admin



回答2:


Use following code

add_action('admin_menu', 'register_custom_menu_page');
 function register_custom_menu_page() {
            add_menu_page( 'admin_menu', 'Logout', '0', 'logout', 'users_add_login_logout_link'); 
        }
        function users_add_login_logout_link(){ ?>
                      <div id="dashboard" class="wrap">
                <div style="float: left; height: 48px margin: 7px 8px 0 0; width: 48px;">
                    <br>
                </div>
                <h2>Log Out</h2>
            </div>
            <div style="text-align: center;"><img src="put you image link" width="128px" height="128px" /></div>
            <div style="text-align: center;">Please wait we are logging you out ...</div>
            <br/>
            <br/>
            <div style="padding: 10px 0; font-size: 25px;"><p>

            </div>
            <?php 
            $location = '"Location: ' . wp_logout_url() . '"';
            echo '<meta http-equiv="refresh" content="4; url=' . wp_logout_url(home_url()) . '"/>';
        }



回答3:


Another alternative, with a dashicon. Based on this answer.

add_action('admin_menu', 'logout_menu_item');
function logout_menu_item() {
    add_menu_page('', 'Logout', 'manage_options', 'logout', '__return_false', 'dashicons-external', 999); 
}

add_action('after_setup_theme', 'redirect_loggingout');
    function redirect_loggingout() {
    if ( isset($_GET['page']) && $_GET['page'] == 'logout' ) {
      wp_redirect( wp_logout_url() );
      exit();
    }
}


来源:https://stackoverflow.com/questions/39806222/add-logout-link-to-wordpress-admin-dashboard-left-sidebar-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!