sinanisler logo

Hiding the WordPress Admin Bar, wp-admin bar

This simple code snippet hides the WordPress admin bar, which is displayed by default for logged-in users. Disabling the admin bar can be useful for a cleaner user experience on the front end, particularly for sites where the admin toolbar is not frequently used or needed by regular users

hiding admin bar for all

add_filter( 'show_admin_bar', '__return_false' );

hiding admin bar for normal users subscribers only

function hide_admin_bar_for_subscribers() {
    if (!current_user_can('administrator') && !is_admin()) {
        $user = wp_get_current_user();
        if (in_array('subscriber', (array) $user->roles)) {
            return false;
        }
    }
    return true;
}

add_filter('show_admin_bar', 'hide_admin_bar_for_subscribers');

Context and Considerations:

  • The admin bar in WordPress provides quick access to admin functionalities like editing posts, accessing the dashboard, and other shortcuts for logged-in users, particularly administrators and editors.
  • Hiding the admin bar can be beneficial for websites where the front-end user experience is prioritized, and the admin functionalities are not needed frequently by the user.
  • This change is especially useful for websites with a significant number of subscribers or members who do not require regular access to the backend functionalities.
  • It’s important to note that this snippet only hides the admin bar; it doesn’t restrict access to the WordPress dashboard or admin area. Users can still access the dashboard by navigating to it directly via URL.
  • Before implementing this, consider the impact on your user’s workflow, as it might affect the ease of access for users who regularly need to switch between front-end and back-end views.

Leave the first comment