? 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;