0

I have a wordpress website, where i am providing customers with user name and password to access my shop.

When a customer logs in, he can see the top wordpress admin bar as well. I dont want users added as "customers" through users>add new to see that bar.

How should i disable this?

2

2 Answers 2

0

If you look at user profile in WordPress administration you would see that there is an option: Show Toolbar when viewing site. If you uncheck this option user will not see an admin bar.

This option is checked by default when user is registering to your store. You can disable it using user_register filter.

function wpse_278096_disable_admin_bar( $user_id ) {

    update_user_meta($user_id, 'show_admin_bar_front', false);
}

add_action( 'user_register', 'wpse_278096_disable_admin_bar', 10, 1 );
4
  • i have added this using php inserter plugin, below another php function (for another purpose). But it doesnt work as expected.
    – patish28
    Commented Nov 30, 2017 at 9:26
  • it has disabled the "show toolbar when viewing site" but by default when i login using that account, it shows the top wordpress bar still.
    – patish28
    Commented Nov 30, 2017 at 9:31
  • Maybe some of installed plugin is overwriting this settings? Try to disable all plugins and check if admin bar is visible for user which has "Show Toolbar when viewing site" unchecked.
    – kierzniak
    Commented Nov 30, 2017 at 9:47
  • yes it worked. One plugin was interfering. Thank you so much.
    – patish28
    Commented Nov 30, 2017 at 11:28
0

Just add the below code to your theme function.php file and you should be good.

add_action('set_current_user', 'customer_hide_admin_bar');
function customer_hide_admin_bar() {
  if (!current_user_can('edit_posts')) {
    add_filter('show_admin_bar', '__return_false');

  }
}
1
  • 1
    i have added this using php inserter plugin, below another php function (for another purpose). But it doesnt work as expected.
    – patish28
    Commented Nov 30, 2017 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.