Recently while working on a membership site, we had to create multiple level of users. We did not want the users to have access to the WP-Admin panel because it was not customized for their experience. Rather we had put everything necessary (such as edit profile page), user dashboard etc, on the front-end. While S2 会员插件 allowed for us to disable wp-admin access for all users except for admins, there was no option to disable the admin bar by default. In this article, we will show you how to disable WordPress admin bar for all users except for Administrators.
最近,在会员网站上工作时,我们不得不创建多个级别的用户。 我们不希望用户访问WP-Admin面板,因为它不是根据他们的体验定制的。 相反,我们已将所有必要的内容(例如,编辑个人资料页面),用户仪表板等放在了前端。 尽管S2 会员插件允许我们对除管理员以外的所有用户禁用wp-admin访问,但是默认情况下没有选项可以禁用管理栏。 在本文中,我们将向您展示如何为除管理员以外的所有用户禁用WordPress管理栏。
影片教学 (Video Tutorial)
如果您不喜欢该视频或需要更多说明,请继续阅读。
如果您不喜欢该视频或需要更多说明,请继续阅读。
对除管理员以外的所有用户禁用管理栏 (Disable Admin Bar for All Users Except for Administrators)
Paste this code in your theme’s functions.php file or your 特定于站点的插件.
将此代码粘贴到主题的functions.php文件或在特定于站点的插件中 。
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
对所有用户禁用管理栏 (Disable Admin Bar for All Users)
If you want to disable it for all users, then simply put use this code in your theme’s functions.php file or your 特定于站点的插件.
如果要对所有用户禁用它,则只需在主题的functions.php文件或在特定于站点的插件中使用此代码即可。
/* Disable WordPress Admin Bar for all users but admins. */
show_admin_bar(false);