Created
February 26, 2015 13:33
-
-
Save duogeekdev/4c59c1da93a4b0692d50 to your computer and use it in GitHub Desktop.
Hide admin bar in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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