How to Get the Admin Color Scheme From a WordPress User’s Profile

While designing the new MD Admin Panel I needed to come up with a way to make the panel look a little creative without going too over-the-top on the design.

Then it dawned on me that WordPress introduced multiple admin color schemes not too long ago and I went off to the races to figure out how I could use that color data myself to reuse.

After digging around, it turns out it’s pretty easy:

    global $_wp_admin_css_colors;

    $admin_color = get_user_option( 'admin_color' );
    $colors      = $_wp_admin_css_colors[$admin_color]->colors;

For use in any PHP function or file. Mind your php tags.

Let’s break it down a little bit:

  1. Call the $_wp_admin_css_colors global variable to get Admin Color Scheme data.
  2. Get the user’s current color scheme choice as set in their profile and store it in the $admin_color variable.
  3. Using the $admin_color variable, trickle down the object to get a list of the admin colors hex codes and store in the $colors variable:
    [0] => #222
    [1] => #333
    [2] => #0073aa
    [3] => #00a0d2

See for yourself: <?php print_r( $colors ); ?>

From there you can pick any color down the list by echo’ing the Array item:

<?php echo $color[2]; ?>

The best part is that the colors will update based on a user’s color choice, so your colors will always stay consistent with any Admin Color Scheme.

About Alex

The 26 year old creator of Marketers Delight.