Do you not need that handy-dandy toolbar at the top of your WordPress website for any user who is not an administrator?
Here’s a little snippet of code you can add to your theme’s functions.php file.
This snippet of code will simply hide the WordPress toolbar from any user who is not an administrator. This means it will be hidden for editors, authors, contributors, subscribers and guests (non-logged in) users.
Show WordPress Toolbar for Administrators Only
if (!current_user_can(‘administrator’)) :
Code snippet originally from Only show admin bar to administrators on wp-snippets.com
As you may have guessed, you can replace administrator with editor to have the toolbar only show up for editors, author for only authors, etc.
Show the WordPress Toolbar for Author Role and Higher
Of course, it is likely you want to show the toolbar for everyone with an author role or higher. To do this, replace administrator with publish_posts This is because everyone who is an author or higher has the ability to publish their own posts. The difference, a contributor cannot publish posts. They must submit a post for approval to be published by an editor or an administrator
To display the toolbar for each role and above, use the following
- guest – get the plugin WordPress Admin Bar Improved. Activating the toolbar for guests really doesn’t do any good unless you add some functionality to it. WordPress Admin Bar Improved allows you to add a simple Ajax login form to the toolbar (and other options), so visitors can login without reloading the page. NOTE: The WordPress Admin Bar Improved will override any of the other user role settings.
- subscriber – do not add a code at all to your functions.php
- contributor – use edit_posts instead of administrator
- author – use publish_posts instead of administrator
- editor – use edit_others_posts instead of administrator
- administrator – use administrator, alternatively, you can use activate_plugins
Want us to add this modification for you?
Send us an email and we can make the toolbar modification on your website very cheap.