Disable The WP Admin Bar
Home » WordPress » How to Disable The WP Admin Bar

How to Disable The WP Admin Bar

How to Disable the WP Admin Bar – The WordPress Admin Bar, also known as the Toolbar, is a convenient feature for quickly accessing various administrative functions from the front end of your WordPress site.

However, there are scenarios where you might want to disable it, either for all users or specific user roles, to provide a cleaner interface or prevent access to admin features directly from the front end.

Why Disable the WP Admin Bar?

Disabling the WP Admin Bar can be particularly useful in the following cases:

  1. Aesthetics: For a cleaner look, especially on sites where the admin bar visually interferes with the theme or design.
  2. Performance: Minimally reducing resource load, as the admin bar doesn’t need to load on the front end.
  3. User Experience: Limiting backend access from the front end for certain user roles, enhancing security, or simplifying the user interface for non-admin users.

How to Disable the WP Admin Bar

You can disable the WP Admin Bar using a plugin for a user-friendly approach or by adding custom code through your theme’s functions.php file or a site-specific plugin. Here’s how to do it:

Method 1: Disable WP Admin Bar Using a Plugin

Plugins provide an easy and reversible way to manage the visibility of the WP Admin Bar. You can use plugins like “Admin Bar Disabler” or “WP Admin UI Customize” to manage its visibility based on user roles.

Steps to use a plugin:

  1. Go to Plugins > Add New in your WordPress admin dashboard.
  2. Search for “Admin Bar Disabler” or a similar plugin.
  3. Install and activate the plugin.
  4. Configure the plugin settings from its settings page to disable the admin bar for all users or specific user roles.

Method 2: Adding Custom Code

Adding custom code allows you more control over when and for whom the admin bar is disabled. You can add this code to your theme’s functions.php file or use a site-specific plugin for better management.

Option 1: Using the Theme’s functions.php File

You can add the following code to your theme’s functions.php file to disable the admin bar. This method is straightforward but can be affected by theme updates.

add_action('after_setup_theme', 'zerobytecode_remove_admin_bar');

function zerobytecode_remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}

This code snippet disables the admin bar for all users except administrators.

Option 2: Using a Site-Specific Plugin for Custom Code Snippets

A site-specific plugin like “Code Snippets” is a safer and more update-proof method compared to modifying theme files directly.

Steps to use a code snippet plugin:

  1. Install the “Code Snippets” plugin from the WordPress plugin repository.
  2. Activate the plugin and navigate to Snippets > Add New.
  3. Paste the code snippet provided above into the new snippet content area.
  4. Title the snippet, such as “Disable Admin Bar for Non-Admins“, and activate it.

Wrapping Up

Choosing between a plugin or custom code depends on your specific needs and comfort level with coding. Both methods provide effective solutions for disabling the WP Admin Bar, enhancing your site’s aesthetics, performance, or security as needed.

Similar Posts