Sarathlal N

Hide / Disable WordPress admin bar

The WordPress automatically generate a admin bar at the top of every pages for logged in users. This admin bar is really an annoyance to some of us in different situations.

Today we are going to hide this admin bar using some simple code snippets.

To hide admin bar completely from front end for all users, put the below code snippet in theme’s / child theme’s functions.php file.

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
show_admin_bar( false );
}

We can hide admin bar for selected users only by adding an if statement with above lines of of code.

add_action('after_setup_theme', 'remove_admin_bar');

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

Now the admin bar is only visible for administrators.

Also we can use WordPress filter hook to hide this admin bar.

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
add_filter('show_admin_bar', '__return_false');
}

Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!

Recent Posts

  1. Automating Code Linting with GitHub Actions for WordPress Plugins
  2. Comprehensive Guide to Linting PHP, JavaScript, and CSS in WordPress Plugins Using Composer
  3. The Ultimate Guide to Indexing in Database Design
  4. Understanding 'update_meta_cache' in WordPress - When to Use It, When Not to, and Its Impact on Database Queries
  5. A Guide to Configuring JavaScript and SCSS Paths in WordPress Plugins with @wordpress/scripts

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.