Search
Close this search box.

How to Hide WordPress Admin Bar for Non-Admin Users (without Plugin)

By default, all logged-in users in WordPress, regardless of their role, see an admin bar at the top of the site. This bar offers quick access to the admin area and editing tools for users with roles such as author or higher.

However, for subscribers and contributors, who have limited access, you might prefer to remove the admin bar or replace it with a more aesthetically pleasing alternative. This adjustment can enhance their experience and keep the interface clean and user-friendly.

Whether you’re aiming to create a more polished site or simply want to keep things tidy without impacting your website’s performance with additional plugins, our guide will walk you through the process with ease and clarity, ensuring you achieve a clean and efficient user experience.

Let’s get started!

Hiding the Admin Bar for Non-Admin Users in WordPress

WordPress Default Option

While WordPress does offer a default option to hide the admin bar, it requires manually unchecking the option in each user’s profile settings. This can become quite cumbersome if you have many users.

Hide Admin Bar for Non-Admin Users with Custom Code.

Fortunately, in WordPress, you can easily hide the admin bar for all non-admin users by adding a custom code snippet. This approach simplifies the process and saves you from manually adjusting settings for each user.

Below, you’ll find the custom code needed to achieve this task effortlessly.

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

The provided snippet will check the user’s role and hide the admin bar for everyone except administrators.

Now, it’s time to integrate the snippet into your WordPress website. The simplest way is to add the code to the functions.php file of your currently active theme.

Alternatively, consider safer methods like using a child theme or creating a custom plugin.

To add the code to the functions.php file, navigate to Appearance → Theme File Editor in your WordPress dashboard (For block themes, locate the Theme File Editor in the Tools menu.). From there, select the functions.php file from the list of theme files and copy the code to the bottom of the file, then click the Update File button to apply the changes.

With this change, users without admin roles will no longer see the admin bar when browsing your website.

Bonus Snippet: Hide Admin Bar for All Users

If you’d like to hide the admin bar for all users, including admins and custom roles, you can use the following code snippet. Simply integrate this snippet into your WordPress website, and you’ll achieve a clean, distraction-free experience for everyone.

/* Hide WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );

The Bottom Line

By following this guide, you can easily customize the visibility of the admin bar on your WordPress site, tailoring the user experience to better suit the needs of your various user roles. This not only enhances the overall aesthetics and usability of your site but also keeps it running smoothly without unnecessary plugins.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Picture of Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to turn your WordPress knowledge into revenue? OF COURSE!

Leave a Comment

Share This
Hey 👋🏻
Do you have a WP blog?
If so, you may need these. All the resources you need to grow your blog.

Your popup content goes here

50%

Where should we send the template?

After entering your email address, you will be added to our newsletter subscribers. You can unsubscribe anytime.

Want to Build Passive Income Like the One on the Screenshot Below?

Click the button on the right side to learn how 👉🏻
5 easy steps to turn your WordPress knowledge into monthly recurring revenue.

Click the above button to close the popup.