I'm trying to get the stylesheet of the currently active admin color scheme to style a plugin to fit into the color context.

As mentioned in this post I had a look at the implementation of admin_color_scheme_picker() in wp-admin/includes/misc.php:564. They use a global variable called $_wp_admin_css_colors but when I try to access (var_dump()) it, it's NULL.

Is there any way to access to actual CSS code?

Why is the global variable NULL? I did a grep -n '$_wp_admin_css_colors' -r . and couldn't find any line where it gets destroyed...


I see it wasn't clear what I exactly want. I don't want to access the actual CSS code, but the color codes that gets parsed into CSS. In wp-includes/general-template.php:2117 the default themes are registered like this:

wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
    admin_url( "css/colors$suffix.css" ),
    array( '#222', '#333', '#0074a2', '#2ea2cc' ),
    array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' )

And I'd like to access the variables like this in PHP. Copying the definition is not an option, since other plugins and themes could add their theme themselves.

3 Answers 3


I actually made it!

In my script file, at the to I define a new variable and copy the $_wp_admin_css_colors variable into it using the admin_head hook, since the variable gets destroyed at some later point:

    global $admin_colors; // only needed if colors must be available in classes
    add_action('admin_head', function() {
        global $_wp_admin_css_colors;
        global $admin_colors; // only needed if colors must be available in classes
        $admin_colors = $_wp_admin_css_colors;

    // more script content...

Both answers are very helpful. Julian's answer grabs all the color schemes in play. tfrommen's answer finds the currently enabled one. If we combine both of those, we can go further and actually use it.

Here's an example that grabs the current color scheme and dynamically inserts a stylesheet with CSS variables corresponding to each color:

class MyTheme
    static $ADMINCOLS = [];
    static function ImprintCols()
        add_action('admin_head', function()
            global $_wp_admin_css_colors; 
            if(!$_wp_admin_css_colors) return;
            $color = get_user_meta(get_current_user_id(), 'admin_color', true);
                self::$ADMINCOLS = $_wp_admin_css_colors[$color];
        add_action('admin_footer', function()
            if(!self::$ADMINCOLS) return;
            $vars = [''];
            foreach(self::$ADMINCOLS->colors as $key=>$col)
                $vars[] = "\t--wp-admin-color-$key: $col;";
                foreach(self::$ADMINCOLS->icon_colors as $key=>$col)
                    $vars[] = "\t--wp-admin-color-icon-$key: $col;";
            $vars[] = '';
            $styles = ":root {".join(PHP_EOL,$vars)."\t}";
            echo '<style id="wp-admin-cols">'.PHP_EOL.$styles.PHP_EOL.'</style>'.PHP_EOL;

This will create a style sheet declaration like the following (here I'm using the delectable Ectoplasm color scheme):

<style id="wp-admin-cols">
:root {
    --wp-admin-color-0: #413256;
    --wp-admin-color-1: #523f6d;
    --wp-admin-color-2: #a3b745;
    --wp-admin-color-3: #d46f15;
    --wp-admin-color-icon-base: #ece6f6;
    --wp-admin-color-icon-focus: #fff;
    --wp-admin-color-icon-current: #fff;

Then any admin-based stylesheet can use these CSS variables, as so:

h1 { border-bottom: 2px solid var(--wp-admin-color-0); }

The color scheme is stored as user meta:

$color = get_user_meta(get_current_user_id(), 'admin_color', true);

However, the CSS file seems to be generated when having chosen another scheme.

So you just need this:

$admin_css_file = wp_admin_css_uri('css/colors');
  • 1
    Please re-read my answer, I clarified, what I really wanted :) Jan 23, 2014 at 17:33

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.