如何为除管理员以外的所有用户禁用WordPress管理栏

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 Membership Plugin 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)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

对除管理员以外的所有用户禁用管理栏 (Disable Admin Bar for All Users Except for Administrators)

Paste this code in your theme’s functions.php file or your site-specific plugin.

将此代码粘贴到主题的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 site-specific plugin.

如果要对所有用户禁用它,则只需在主题的functions.php文件或特定于站点的插件中使用此代码即可。


/* Disable WordPress Admin Bar for all users but admins. */
  show_admin_bar(false);

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-disable-wordpress-admin-bar-for-all-users-except-administrators/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值