5

I need to change default color scheme for all users. The admin bar on my site is vidibile for all users including guests. The default black color scheme isn't beauty with my design and I would like to change it with cofee scheme. Is there any way to do this?

I already found

add_filter('get_user_option_admin_color','change_admin_color');
function change_admin_color($result) {
   return 'coffee';
}

But it disable feature to choose another color scheme for users. And first of all it work only for logged in users.

4

At the moment (3.8) color schemes do not apply to admin bar at front end at all, even if user is logged in and has non-default scheme selected.

The shortest way would probably be to force enqueue color scheme at front end:

add_action(
    'wp_enqueue_scripts',
    function () {
        wp_enqueue_style(
            'color-admin-bar',
            admin_url( '/css/colors/coffee/colors.min.css' ),
            array( 'admin-bar' )
        );
    } );

Note that core chose not to do it, so it is untested and there is risk of style incompatibilities and such.

  • May be not the best way, but it works perfectly. Like I need. Thank you! – okonik Dec 14 '13 at 21:56
1

You can setup a theme on profile update, and if it present return that from the function hooking get_user_option_admin_color otherwise return the default:

add_action('profile_update', function($user_id) {
  // on profile update save the unfiltered color choice in an additional meta
  $set = get_user_meta('admin_color', $user_id, true) ? : 'coffee';
  update_user_meta($user_id, '_setted_admin_color', $set);
});

add_filter('get_user_option_admin_color','change_admin_color');

function change_admin_color($result) {
   $color = 'coffee';
   if ( is_user_logged_in() ) { // for nono logged user output default
      // get the unfiltered color meta
      $setted = get_user_meta( get_current_user_id(), '_setted_admin_color', true );
      // if present set color to that
      if ( ! empty($setted) ) $color = $setted;
   }
   return $color;
}

Code require PHP 5.3. Untested.

  • Thank you a lot, but it works only for logged in users. – okonik Dec 14 '13 at 21:50
0

https://wordpress.org/plugins/admin-bar-color/ works, is light-weight, well written and on GitHub.

I had to re-save my profile once, but now my frontend admin bar color matches /wp-admin/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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