Created
September 9, 2022 13:17
-
-
Save terrytsang/2bab48e4227db36d6bac82dc32cf22ad to your computer and use it in GitHub Desktop.
How to hide WordPress Admin bar for all/non-admin users
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 | |
//below code snippet is to be added to WordPress theme functions.php file | |
//option 1: remove the WordPress admin bar for all users | |
add_filter('show_admin_bar', '__return_false'); | |
//option 2: hide the WordPress admin for everyone except users with administrator privileges | |
add_action('after_setup_theme', 'remove_admin_bar'); | |
function remove_admin_bar() { | |
if (!current_user_can('administrator') && !is_admin()) { | |
show_admin_bar(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment