hide the wordpress admin bar
I recently came across a client that needed a website where users must login to view the site. The users, however, had no reason to see the admin panel or use it. The snippet of code below will eliminate the admin panel for users labeled as “subscribers”.
This code goes in functions.php of your theme.
/**
* Disable admin bar on the frontend of your website
* for subscribers.
*/
function themeblvd_disable_admin_bar() {
if( ! current_user_can(‘edit_posts’) )
add_filter(‘show_admin_bar’, ‘__return_false’);
}
add_action( ‘after_setup_theme’, ‘themeblvd_disable_admin_bar’ );/**
* Redirect back to homepage and not allow access to
* WP admin for Subscribers.
*/
function themeblvd_redirect_admin(){
if ( ! current_user_can( ‘edit_posts’ ) ){
wp_redirect( site_url() );
exit;
}
}
add_action( ‘admin_init’, ‘themeblvd_redirect_admin’ );
* Disable admin bar on the frontend of your website
* for subscribers.
*/
function themeblvd_disable_admin_bar() {
if( ! current_user_can(‘edit_posts’) )
add_filter(‘show_admin_bar’, ‘__return_false’);
}
add_action( ‘after_setup_theme’, ‘themeblvd_disable_admin_bar’ );/**
* Redirect back to homepage and not allow access to
* WP admin for Subscribers.
*/
function themeblvd_redirect_admin(){
if ( ! current_user_can( ‘edit_posts’ ) ){
wp_redirect( site_url() );
exit;
}
}
add_action( ‘admin_init’, ‘themeblvd_redirect_admin’ );
There are no comments published yet.