Sometimes we want to remove the admin tool from front-end websites based on the user role and permission on your site. In this post, I have explained the simple and easy codes to remove admin toolbar on the user role basis.
Use the below code at the end of the wp-content/themes/your-theme/functions.php file. It will remove the Admin toolbar for all users except the Administrators.
1 2 3 4 | // show admin bar only for admins if (!current_user_can('manage_options')) { add_filter('show_admin_bar', '__return_false'); } |
Below code will remove the Admin bar from front-end sites for Administrators as well editors of your web
1 2 3 4 | // show admin bar only for admins and editors if (!current_user_can('edit_posts')) { add_filter('show_admin_bar', '__return_false'); }admin_bar', '__return_true' , 1000 ); |
Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners