Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/PHP/Hide WordPress Admin Bar

June 6, 2014

Hide WordPress Admin Bar

There are reasons why you want to hide the Admin Bar from your users. If users don’t have edit rights, then there’s really no use for an Admin bar. Another reason is if the account is shared with others, you don’t want users to reset the password. There are ample reasons why you want to hide the Admin bar.

Here’s the code:

if (!current_user_can(‘edit_posts’)) {
  show_admin_bar(false);
}

if (!current_user_can(‘edit_posts’)) { show_admin_bar(false); }

Here’s another:

function my_function_admin_bar(){ return false; }
add_filter( 'show_admin_bar' , 'my_function_admin_bar');

function my_function_admin_bar(){ return false; } add_filter( 'show_admin_bar' , 'my_function_admin_bar');

Here’s another for users that can’t manage options:

if ( ! current_user_can( 'manage_options' ) ) {
  show_admin_bar( false );
}

if ( ! current_user_can( 'manage_options' ) ) { show_admin_bar( false ); }

And one more for good measure:

add_action('set_current_user', 'csstricks_hide_admin_bar');
function csstricks_hide_admin_bar() {
  if (current_user_can('edit_posts')) {
    show_admin_bar(false);
  }
}

add_action('set_current_user', 'csstricks_hide_admin_bar'); function csstricks_hide_admin_bar() { if (current_user_can('edit_posts')) { show_admin_bar(false); } }

Filed Under: PHP, WP Tagged With: admin bar

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021