Show Toolbar to Administrators Only

Show Toolbar to Administrators Only

? The Snippet:

// Check if user is Administrator or Not
if (!current_user_can('administrator')) :
  show_admin_bar(false);
endif;

ℹ️ About the Snippet

In WordPress, after each user registration by default they can see the WP toolbar on front-end/backend. This Toolbar is unnecessary for many of the sites like shopping stores and membership websites. This toolbar should only be limited to website admins only.

To disable the toolbar, you’ve to change preferences for every user from Users -> Edit (Profile) but customizing too many profiles is tedious. With this small snippet, you can show the Toolbar to the website’s administrators only. No other user will be able to see the Toolbar after logging in.

✅ How to use the Snippet

It would be helpful to use this snippet if you had a basic understanding of editing theme files. Add the below code snippet to theme’s funtions.php file, and it will disable Toolbar for all other users except the admins of the website.

// Check if user is Administrator or Not
if (!current_user_can('administrator')) :
  show_admin_bar(false);
endif;

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get regular WordPress updates directly in your inbox.

shares