Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More โHide WordPress admin toolbar for all users except administrators using show_admin_bar filter and current_user_can function. Simple security enhancement to prevent non-admin users from seeing admin bar on frontend while maintaining admin access.
To hide the WordPress admin bar for all users except the site administrator, you can use the `show_admin_bar` filter in combination with the `current_user_can()` function. Here's how you can implement it:
// Disable admin bar for users without admin access
function hide_admin_bar_for_non_admins() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
add_action('after_setup_theme', 'hide_admin_bar_for_non_admins');
This function hooks into the `after_setup_theme` action, ensuring it runs early during WordPress initialization. It checks if the current user lacks the 'administrator' capability and is not in the dashboard. If those conditions are met, `show_admin_bar(false)` disables the toolbar for that user. Add this snippet to your theme’s `functions.php` or in a custom plugin. Don’t forget to test it using a non-admin account to verify that the admin bar is hidden appropriately. 
Search our archives or reach out to our team for solutions and expert advice.