功能current_user_can指的是功能或用户角色名称。因此,尝试manage_options代替:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
// 'manage_options' is a capability assigned only to administrators
if (!current_user_can('manage_options') && !is_admin()) {
show_admin_bar(false);
}
}
而不是使用after_setup_theme行动,你还可以添加一个过滤器(者优先用于新的WP版本)的:
add_filter('show_admin_bar' , 'handle_admin_bar');
function handle_admin_bar($content) {
// 'manage_options' is a capability assigned only to administrators
// here, the check for the admin dashboard is not necessary
if (!current_user_can('manage_options')) {
return false;
}
}
thanx您的帮助,但不工作的代码。 – Toasty
你在哪里放置这段代码?它应该在你主题的** functions.php **开头。 – xphan
这段代码的位置是否有效?我有我以前在我的functions.php文件中指出了独立的PHP文件,并且工作。 Wil试试你的解决方案,然后回来,结果 – Toasty