WordPress admin bar contains many interesting and convenient links for admins and editors. But it is totally useless, redundant and confusing for regular users.
Here is how to hide it for subscribers while viewing the site.
Open your theme functions.php file and add these lines at the very end:
if(current_user_can('subscriber')) add_filter( 'show_admin_bar', '__return_false' );
To hide Admin bar while users are in Control Panel, you need to add these lines at the end of your theme style.css file:
#wpadminbar { display: none; visibility: hidden; }
The final questions to answer:
-01- Can we do all these changes one file and
-02- How to remove an ugly empty space at the top of the screen in Control Panel?
-03- How to display a link that will return users from Control Panel back to the site?
[2012-02-17 FR 09:18]
There is a way to hide WP Admin bar conditionally both on the site and in Control Panel. This example is from theme functions.php:
// Hide WordPress Admin Bar in Control Panel function hide_AdminBar() { $hide_AdminBar = "<style type=\"text/css\"> #wpadminbar { display: none; visibility: hidden; } </style>"; print($hide_AdminBar); } if(current_user_can('subscriber')) { // Hide WordPress Admin Bar in Control Panel add_action( 'admin_head', 'hide_AdminBar' ); // 2012-02-14 TU 17:16 Hide WordPress Admin Bar whlile viewing add_filter( 'show_admin_bar', '__return_false' ); }
Here you hide admin bar for Subscribers only both in control Panel and while viewing the site. And you only touching one file – functions.php. No changes are requred in styles.css.
Still, two major problems remain with this solution:
– Remove empty space on the top of the screen in Control Panel;
– Add a link back to your site.
[2012-04-18 WE 10:23]
To resolve the issue with empty space on top of subscribers control panel, we decided not to hide the admin bar, but just to remove WP Logo button in the upper left corner of the screen:
if(current_user_can('subscriber')) { add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' ); } . . . function mytheme_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); }
This solution:
(01) returns the bar for subscribers only in control panel view;
(02) it consumes the empty space, and
(03) it allows to utilize any future improvements that WP might to offer.
Be the first to comment