1
votes

Im using Redux Framework and Trying to Activate or Deactivat wordpress admin bar with this function

if( !function_exists('mytheme_admin_bar') ){
function mytheme_admin_bar(){
global $optname; 
if( $optname['hide_admin_bar'] == 1 && !current_user_can('manage_options') ) {
return true;
    } else {
return false;
  }
}
add_filter( 'show_admin_bar' , 'mytheme_admin_bar');
}

Thats working fine but Im confused because when The value is false its hiding the admin bar also for Administrator do u have any idea how to make a function like this but to effect to all users except Administrator, I dont want to hide admin bar for admins

thankyou

3

3 Answers

0
votes

I typically add the following to the themes functions.php file.

wp-content/themes/themename/functions.php

show_admin_bar(false);

This removes it from the front end totally, for that theme - provided simply as a fallback here since it's not exactly what you're asking!

0
votes

You need to check if the user is admin. So here is a wrapper

if (is_admin()) { 

  add_filter( 'show_admin_bar' , true);


 } else {
  add_filter( 'show_admin_bar' , false);
}

Basically you are checking if the user is not an admin than fire this code snippet. Hope it helps.

0
votes

Use this code, it doesn't hide it for Administrator

add_filter('show_admin_bar', '__return_false');