5

Is it possible to have a different back-end colour scheme selected for the different sites of a multisite?

i.e. "Sunrise" for Site A and "Midnight" for Site B

If it's not possible for the user to setup could it be enforced through a plugin or the theme?

3 Answers 3

3

Add to your functions.php file the following code, this will hook into your admin header section and will place the style you chose accordingly to the matching site.

add_action('admin_enqueue_scripts', 'my_admin_background');

function my_admin_background() {
  wp_enqueue_style(
    'custom-style',
    get_template_directory_uri() . '/css/custom_script.css'
  );
      global $blog_id;
      $color = '';
      if ($blog_id == 1) {
         $color = 'white';
      } elseif ($blog_id == 2) {
         $color = 'red';
      } elseif ($blog_id == 3) {
         $color = 'blue';
      } else {
         $color = 'yellow';
      } 
      $custom_css = "<style> body { background: $color } </style>";
  wp_add_inline_style( 'custom-style', $custom_css );
}
5
  • This plugin only seems to add CSS to the front-end of the sites. I am searching for a way to change the back-end look to make it easier to distinguish the sites at a glance. Jul 1, 2014 at 8:12
  • Check my edited answer, this should do the job.
    – elvismdev
    Jul 1, 2014 at 20:52
  • Rather than dump the CSS into the <head> of the backend, consider using the function wp_add_inline_style(). To use in in the backend, you can hook it to the admin_enqueue_scripts action hook instead of wp_enqueue_scripts as shown in the Codex page's example.
    – Pat J
    Jul 1, 2014 at 21:10
  • You'r right @PatJ , I think now is a better code.
    – elvismdev
    Jul 1, 2014 at 22:25
  • Thanks! This got me what I wanted. I changed it a bit though to directly enqueue the stylesheet depending on the $blog_id, as that saves me the hassle of figuring out the specific selectors to overwrite with a custom style. Jul 2, 2014 at 8:10
1

A better way to do this would be to use the "get_user_option_admin_color" filter. This way you can choose an already created colour scheme which it seems like the question was asking for.

add_filter('get_user_option_admin_color', 'change_admin_color');
function change_admin_color($result) {
if(get_current_blog_id() == 2) {
    return "light";
}
else {
    return "midnight";
}
1
  • v.helpful: for multiple color schemes, of course, add an "elseif" statement
    – jadik
    Jul 21, 2021 at 5:56
-1

This is some sample code needed for making an individual color scheme.

wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
    '#07273E', '#14568A', '#D54E21', '#2683AE'
) );

Source file: wp-includes/general-template.php

/**
 * Register color schemes.
 */
 function add_colors()

Example: Scroll down to find the color scheme that you duplicated, and copy all the code, paste it at the bottom of that function, and give it your custom color scheme name. In the end, the bottom two options (before the function is closed) should look something like this:

wp_admin_css_color(
 'seashore', __( 'Seashore', 'admin_schemes' ),
 plugins_url( "seashore/colors$suffix.css", __FILE__ ),
 array( '#F8F6F1', '#d5cdad', '#7D6B5C', '#456a7f' ),
 array( 'base' => '#533C2F', 'focus' => '#F8F6F1', 'current' => '#F8F6F1' )
 );

wp_admin_css_color(
 'matt', __( 'Matt', 'admin_schemes' ),
 plugins_url( "matt/colors$suffix.css", __FILE__ ),
 array( '#1F2C39', '#2c3e50', '#1abc9c', '#f39c12' ),
 array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
 );
6
  • Answers should be more than plain links. Please file an edit and add all relevant info in your answer. Thank you :-) Apr 13, 2015 at 18:01
  • Thank you for adding the block div to make it easier to read Pieter.
    – a4jp.com
    Apr 13, 2015 at 18:35
  • Pleasure :-). Tip: If you add code in the editor, highlight the code, and click on the {} button above the editor, this will add your code in a code block. Alternatively, indent each line of code with 4 spaces. :-) Apr 13, 2015 at 18:36
  • Okay. Thank you. Do I still get minus points even though I edited the post?
    – a4jp.com
    Apr 13, 2015 at 18:38
  • Downvotes depends on other users. Bad or not so good quality answers/questions usually attract downvotes. However, downvotes can be removed with proper edits, like I have done. I only have control over my downvote. Whether or not the other downvote will be removed depends on the user who gave it. If he sees fit, he will remove the downvote. We all go down that route at some stage where an answer or question gets downvoted. You should never take that personally. Downvotes (like upvotes) are merely an indicator how useful someone found your post. Never ever let downvotes get to you :-) Apr 13, 2015 at 18:45

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.