How to Disable the Admin Bar in WordPress

The WordPress admin bar, also known as the toolbar, is a convenient feature that provides quick access to various administrative functions while you are logged in to your WordPress website. However, there may be instances where you want to disable the admin bar for certain users or for all users. In this article, we will explore different methods to disable the WP admin bar in WordPress.

1. Disable Admin Bar for All Users (with PHP Code)

If you want to disable the admin bar for all users on your WordPress website, you can do so by adding a simple code snippet to your theme’s functions.php file. Here’s how:

function disable_admin_bar() {
    show_admin_bar( false );
}
add_action( 'after_setup_theme', 'disable_admin_bar' );

This code snippet will disable the admin bar for all users, including administrators. Once you have added the code to your functions.php file, save the changes and refresh your website to see the admin bar removed.

2. Disable Admin Bar for All Users Except Administrator (with PHP Code)

If you want to disable the admin bar for all users except the administrator, you can modify the previous code snippet to achieve this. Here’s the updated code:

function disable_admin_bar_except_admin() {
    if ( ! current_user_can( 'administrator' ) ) {
        show_admin_bar( false );
    }
}
add_action( 'after_setup_theme', 'disable_admin_bar_except_admin' );

This code snippet checks if the current user is not an administrator and then disables the admin bar. Administrators will still see the admin bar when logged in, while other users won’t. Save the changes to your functions.php file and refresh your website to see the updated admin bar settings.

3. Disable Admin Bar for Specific Roles (with PHP Code)

If you want to disable the admin bar for specific user roles, you can modify the code snippet further. Here’s an example of how to disable the admin bar for the “editor” and “author” roles:

function disable_admin_bar_specific_roles() {
    $user = wp_get_current_user();
    $allowed_roles = array( 'editor', 'author' );

    if ( array_intersect( $allowed_roles, $user->roles ) ) {
        show_admin_bar( false );
    }
}
add_action( 'after_setup_theme', 'disable_admin_bar_specific_roles' );

This code snippet checks if the current user has either the “editor” or “author” role and then disables the admin bar accordingly. You can customize the $allowed_roles array to include or exclude specific roles as per your requirements.

4. Just Installing a Plugin

If you prefer a simpler solution without modifying any code, you can disable the admin bar by installing a plugin. There are several plugins available in the WordPress plugin repository that allow you to disable the admin bar with just a few clicks. Some popular options include “Hide Admin Bar” and “Remove WP Admin Bar”. Simply search for these plugins in your WordPress dashboard, install and activate the one that suits your needs, and the admin bar will be disabled.

Remember to choose a reputable and regularly updated plugin to ensure compatibility with your WordPress version and other plugins.

By following any of the methods mentioned above, you can easily disable the WP admin bar in WordPress. Whether you prefer to use PHP code or a plugin, these options provide flexibility in customizing the admin bar visibility based on your specific requirements.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from WP Notch

Level up your skills. Get expert tips delivered straight to you. Subscribe!

Continue Reading