I have a membership site. I need to disable the admin bar for the subscribers.
I have used this code below:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
which removes the admin bar from the frontend for the subscriber, but when they go to their profile page wp-admin/profile.php, the admin bar is still showing there.
I am using Paid Membership Pro plugin which I think made the code not working on the backend for subscribers.
Also, I have used this code to remove the admin bar from everywhere:
if (!function_exists('disableAdminBar')) {
function disableAdminBar(){
remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
function remove_admin_bar_style_backend() {
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
}
}
add_filter('admin_head','remove_admin_bar_style_backend');
But this code is also not working.
I just want to remove the admin bar for the subscribers from both the frontend and backend pages.
Is there any specific code I am missing? I am using Paid membership Pro.
Thank you for helping.
6 Answers
I did a quick research on this and I don’t think you can with a function, as said in the codex.
Note: It is no longer possible to hide the Toolbar when viewing the Administration Screens, but users can disable it on the front-end of the site in their Profile screen.
Disabling in the frontend results in the same as you’ve already done.
I would suggest hiding it with css.
#wpadminbar {
display: none;
}
html {
padding-top: 0; // Move up the page's content by the bar's height
}