Skip to content

Instantly share code, notes, and snippets.

@duogeekdev
Created February 26, 2015 13:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duogeekdev/4c59c1da93a4b0692d50 to your computer and use it in GitHub Desktop.
Save duogeekdev/4c59c1da93a4b0692d50 to your computer and use it in GitHub Desktop.
Hide admin bar in WordPress
<?php
// Simple way
add_filter( 'show_admin_bar', '__return_false' );
// Standard way
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
function show_admin_bar_cb() {
return false;
}
// Hide admin bar for all users except admin
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
function show_admin_bar_cb() {
if( is_super_admin() )
return true;
return false;
}
// Hide admin bar for all users except admin (shorter version)
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
function show_admin_bar_cb() {
return is_super_admin();
}
// Hide admin bar for subscribers only
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
function show_admin_bar_cb() {
$user = wp_get_current_user();
if( in_array( "subscriber", (array) $user->roles ) ) {
return false
}
return true;
}
// Hide admin bar for subscribers only (shorter version)
add_filter( 'show_admin_bar', 'show_admin_bar_cb' );
function show_admin_bar_cb() {
$user = wp_get_current_user();
return ! in_array( "subscriber", (array) $user->roles );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment