Grow your CSS skills. Land your dream job.

Last updated on:

Remove Admin Bar For Subscribers

You might want open registration on your WordPress site so that (for one small example) people can log in and leave comments on things without needing to type their name/url/email every time. But these users probably don't need to see the whole top admin bar as there likely isn't much use in it for them. Although do be sure to provide a link to edit their profile and log out.

This would be for your functions.php file or functionality plugin:

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

Comments

  1. Permalink to comment#

    Didn’t work for me. It still shows up for all users. Is it a problem with the set_current_user hook? I ended up using on of the options in this article: http://digwp.com/2011/04/admin-bar-tricks/#disable-for-non-admins.

  2. Hiya, just wanted to let you know your code works fine in 3.5.1 Admin bar shows up for admins, but not normal subscriber level users.

  3. I couldn’t get it to work. set_current_user is a depreciated function. I hooked it to wp_footer instead and it did the trick. Although, it’s still adding 28px padding to the top of the html tag.

  4. Permalink to comment#

    i’m using S2 member plugin, can i use this code in function.php…?

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like ```this```. You don't need to escape code in backticks, Markdown does that for you.

Sadly, it's kind of broken. WordPress only accepts a subset of HTML in comments, which makes sense, because certainly some HTML can't be allowed, like <script> tags. But this stripping happens before the comment is processed by Markdown (via Jetpack). It seems to me that would be reversed, because after Markdown processes code in backticks, it's escaped, thus safe. If you think you can fix this issue, get in touch!

If you need to make sure the code (typically HTML) you post absolutely posts correctly, escape it and put it within <pre><code> tags.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".