Disable Admin Bar for Non-Admins

By default, WordPress displays the admin bar for all logged-in users. While this is useful for administrators, it can clutter the frontend experience for subscribers, customers, or other user roles. This snippet hides the admin bar for all non-admin users, giving your site a cleaner, more professional appearance.

<?php
/**
 * Disable Admin Bar for Non-Admin Users
 *
 * This function hides the WordPress admin bar on the front end
 * for all users except administrators.
 */
function wpsnippetpress_disable_admin_bar() {
    if ( ! current_user_can( 'administrator' ) ) {
        show_admin_bar( false );
    }
}
add_action( 'after_setup_theme', 'wpsnippetpress_disable_admin_bar' );
PHP

Usage:

Removes the WordPress admin bar for all non-admin users, keeping the frontend clean for subscribers and customers.

Benefits:

  • Cleaner Frontend – Non-admin users see a streamlined site without the WordPress admin bar.

  • Better User Experience – Ideal for subscribers, customers, or community users.

  • Lightweight & Safe – No plugins needed; simple, efficient code snippet.

Frequently Asked Questions

Yes. Modify the current_user_can() function to check for specific roles, e.g., editor, author, or subscriber.
No. Administrators will still see the admin bar on the frontend. Only non-admins are affected.
Absolutely. This snippet only alters frontend behavior and doesn’t modify core files.

Related Links

Related Snippets

Disable Gutenberg (Block Editor)

Disable the Gutenberg (Block Editor) in WordPress using a simple code snippet. Once disabled, WordPress...

Display Gravity Forms Entries for the Logged-In User

Display Gravity Forms submissions for logged-in users on the frontend using a simple shortcode. Learn...
Picture of Kishan D
Kishan D
I’m a web developer who builds with WordPress, WooCommerce, and Shopify, and I enjoy exploring React and creating gaming & tech content.

SHARE POST

Leave a Reply