How to Hide Admin Bar Based On User Roles or Specific Users?

Imagine a command center where all the tools you need are just a fingertip away; that’s the WordPress Admin Bar for you. This sleek, horizontal black bar is the pulse of your WordPress site, offering a gateway to the engine room where all the magic happens. From swiftly adding a new post to tweaking your profile, the Admin Bar is the trusty sidekick for every logged-in user.

But what if this sidekick becomes a distraction? Or what if you’re the maestro of a symphony, and not every musician needs to tune the instruments? The Admin Bar, while a marvel for site administrators, might not be necessary for every user role. It’s like having a Swiss Army knife when you only need a spoon.

The Admin Bar is your dashboard’s dashboard, a quick-access panel to the beating heart of your site’s operations. It’s there on both the front end and back end, whispering the secrets of seamless site management. Yet, sometimes, silence is golden, and minimalism is the key to efficiency.

In this post, we’ll dive into the why and how of taming this powerful toolbar, ensuring it serves its purpose without overwhelming your ensemble of users.

Why Hide the Admin Bar?

The admin bar can be a useful shortcut for users who frequently manage content or settings on a WordPress site. However, for users with more limited roles, or aesthetic reasons, you might want to streamline their experience by hiding this feature. Doing so can reduce confusion for less technical users, improve site security by minimizing the visibility of admin features, and create a cleaner interface that focuses on content rather than administration.

Hide Admin Bar Based On User Roles

To hide the admin bar for specific user roles, you can add the following code to your theme’s functions.php file:

function hide_admin_bar_based_on_role() {
if (current_user_can('editor') || current_user_can('author') || current_user_can('subscriber')) {
add_action('after_setup_theme', 'hide_admin_bar_based_on_role');

This code checks if the current user has the role of editor, author, or subscriber, and if so, hides the admin bar.

While managing user roles and the visibility of the Admin Bar is crucial, ensuring the security of your WordPress dashboard is equally important. In our comprehensive guide, “How WP-Admin Redirects to Homepage & Hide Login URL?,” we delve into the steps you can take to protect your site’s backend by redirecting the WP-Admin page to the homepage and hiding your login URL. This not only fortifies your site’s defenses but also simplifies the login process for authorized users.

Hiding the Admin Bar for Specific Users

If you want to hide the admin bar for specific users, regardless of their role, you can use their user ID to do so:

function hide_admin_bar_for_specific_users() {
$user = wp_get_current_user();
if (in_array($user->ID, array(2, 4))) { // Replace 2, 4 with the user IDs you wish to hide the admin bar for
add_action('after_setup_theme', 'hide_admin_bar_for_specific_users');

Replace 2, 4 with the user IDs for whom you want to hide the admin bar.

In addition to customizing the Admin Bar, you might also want to declutter your WordPress dashboard by addressing persistent admin notices. Our tutorial, “How to Permanently Hide Admin Notice in WordPress?,” provides a straightforward solution to keep your dashboard clean and distraction-free. By following our guide, you can focus on what truly matters: creating and managing content without unnecessary interruptions.

How to get the User ID?

Just navigate to the Users Page in your WordPress Dashboard. Hover on the “Edit” option for that user for whom you like to hide the admin bar. Take a look at the following screenshot and you will get the ID marked by an arrow sign.

Get the User ID in WordPress Dashboard

Customizing the visibility of the admin bar based on user roles or specific users can greatly enhance the user experience on your WordPress site. By implementing the above code snippets, you can ensure that each user interacts with your site in a way that’s tailored to their needs and your site’s design. Remember to always back up your site before making changes to the code, and happy customizing!

Avatar of Roy Jemee

Roy Jemee

This is Roy and I produce content, Video, and Documentation for WP Adminify plugin Users. Keeping you updated through posts, and videos is my duty. Also, I provide support for any users to solve their problems.

© 2021-2024 - Adminify | All rights reserved

WP Adminfy accepted payment methods