Skip to content

Instantly share code, notes, and snippets.

@rveitch
Created August 1, 2015 23:08
Show Gist options
  • Select an option

  • Save rveitch/3f3828d3ac9e00bdf4c4 to your computer and use it in GitHub Desktop.

Select an option

Save rveitch/3f3828d3ac9e00bdf4c4 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