添加注销链接到WordPress管理仪表板左侧边栏菜单

问题描述:

我想添加注销链接(按钮)在我的WordPress的管理仪表板的左侧。喜欢上图片,我该怎么做?添加注销链接到WordPress管理仪表板左侧边栏菜单

enter image description here

+0

你做了什么?请看看http://stackoverflow.com/help/how-to-ask –

+0

我认为这是一个正确的问题。我发现了一些关于add_menu_page()的信息;但我想添加注销链接而不是页面。此注销按钮不是真实的,我只是想将右上角仪表板下拉菜单中的注销(注销)移至我的左侧管理仪表板菜单,如图中所示。 –

修订

可以实现这一目标使用admin_init行动钩和global $menu

下面是该代码:

add_action('admin_init', 'text_domain_logout_link'); 

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

此代码放在你的活跃儿童主题(或主题)的function.php文件或也以任何插件文件。

代码已经过测试并且功能完整。


参考文献:

+0

完美!它的工作原理,但调试器显示我: 注意:未定义抵消:4 /home/usr/public_html/folder/wp-admin/includes/menu.php线309 注意:未定义抵消:4在/ home /usr/public_html/folder/wp-admin/includes/menu.php 329行 注意:未定义偏移量:4位于/home/usr/public_html/folder/wp-admin/includes/menu.php在线224 我该如何解决它? –

+0

非常感谢你!!!!!!!它完美的工作!有没有办法添加一些dashicon到这个链接? ^^ –

+0

我还在努力的图标。 :( –

使用下面的代码

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()) . '"/>'; 
     } 

另一种选择,具有dashicon。基于此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(); 
    } 
}