Site icon Orion Origin

How to define your own WordPress color scheme and set it as default for all users

WOO color

A wordpress admin color scheme is simply a set of colors which define the look and feel of the admin area. By default WordPress comes with 8 different admin color schemes. Defining yours is easy. Just follow the guide 🙂

 

Achieving our goal will only take 2 steps:

1-Create the color scheme

There are 2 ways to create the color theme: the hardest one which is to create it yourself or generate it. Like my daddy use to say, if you don’t want to waste time, just hang the time wasters! So let’s just go for the easiest way here 🙂 : access http://themergency.com/generators/admin-color-scheme-generator, fill the form, generate and download your color scheme in a zip file.

There are two ways to add the generated color scheme to your wordpress installation:

require_once get_template_directory() . '/darkblue-admin-color-scheme/darkblue-admin-color-scheme.php';

Then you need to edit the darkblue-admin-color-scheme.php file. Search for the add_color_scheme function. Inside this function, replace the second parameter of the wp_admin_css_color “ plugins_url( your_colorscheme.css’, __FILE__ )” by the url of your color scheme main css file “get_template_directory() . ‘/your-admin-color-scheme-folder/’.’your_colorscheme.css’” in my case:

get_template_directory() . ‘/darkblue-admin-color-scheme/’.’darkblue.css’

2. Set the color scheme as default for all user

Now add the following code to the function.php file of your theme. This code simply returns the color scheme you want when wordpress query the current user color scheme from database.

add_filter( 'get_user_option_admin_color', function( $color_scheme ) {

$color_scheme = 'your_color_sheme_name';

return $color_scheme;

}, 5 );

This set the chosen color scheme as default but it doesn’t remove the admin color scheme picker from the profile page. To achieve that, you can add this code to your function.php file:

remove_action("admin_color_scheme_picker", "admin_color_scheme_picker");
Exit mobile version